C# vs c++ vs java - Which should I choose and why?

528    Asked by alexDuncan in Java , Asked on Oct 13, 2022

 C# seems to be popular these days. I heard that syntactically it is almost the same as Java. Java and C++ have existed for a longer time. For what reasons should I choose C# over Java and C++?


Answered by Antony Bence

c# vs c++ vs java


C# is better than C++ in that:

It has native garbage-collection.

It allows you to treat class-methods' signatures as free functions (i.e. ignoring the statically typed this pointer argument), and hence create more dynamic and flexible relationships between classes. edit if you don't know what this means, then try assigning a member method returning void and accepting void to a void (*ptr)() variable. C# delegates carry this pointer with them, but the user doesn't always have to care about that. They can just assign a void() method of any class to any other void() delegate.

It has a huge standard library with so much useful stuff that's well-implemented and easy to use.

It allows for both managed and native code blocks.

Assembly versioning easily remedy DLL hell problems.

You can set classes, methods and fields to be assembly-internal (which means they are accessible from anywhere within the DLL they're declared in, but not from other assemblies).

C# is better than Java in that:

Instead of a lot of noise (EJB, private static class implementations, etc) you get elegant and friendly native constructs such as Properties and Events.

You have real generics (not the bad casting joke that Java class generics), and you can perform reflection on them.

It supports native resource-management idioms (the using statement). Java 7 is also going to support this, but C# has had it for a way longer time.

It doesn't have checked exceptions :smile: (debatable whether this is good or bad)

It's deeply integrated with Windows, if that's what you want.

It has Lambdas and LINQ, therefore supporting a small amount of functional programming.

It allows for both generic covariance and contravariance explicitly.

It has dynamic variables, if you want them.

Better enumeration support, with the yield statement.

It allows you to define new value (or non-reference) types.



Your Answer

Interviews

Parent Categories