The difference between the programming language C# and C++

Firstly, with C #, only .NET applications can be created (actually C # is made for .NET), but with C ++, they can write both .NET managed and native applications.

Secondly, C ++ is the first and last choice for low-level tasks (like Device Driver) and heavy (like 3D games).

C # is designed to be much easier, cleaner, and more streamlined than C ++, and also has better support than C for object-oriented. C # is completely object-oriented and you can not write a non-object-oriented program at all, if you can write both program-oriented and non-object oriented C ++.

C # feature:

1- Automatic memory management by CLR

2- Support for an internal String type

3. Support foreach

4. Full delegate and event and interface support and Property and attributes

5 - XML ​​Documentation

6 - checked / unchecked keywords

And ...

In C #, you can use the .NET class to do all the tasks, while in C #, we do not have any header and #include files. In fact, C # is much more beautiful than C ++, because in any case, C # has been taught to learn languages ​​such as C ++, JAVA and Delphi, and the errors in those languages ​​are repeated in C #.
For example, in C ++, the number of fingers is the type of String data. Or Multiple Inheritance, which is very troublesome, for example, in JAVA, enum and Operator Overloading, and Pointer and Properties, all of which are considered necessary. Of course, those who want to do a hefty or low level work on .NET, usually write all the parts they can do with C #, and the rest with C ++, and in C # use the classes written in C ++. (Wrapper Classes) In general, C # is a high level of C ++; in C ++, you can even use the assembly code directly.

Meanwhile C # is the first Component Oriented language in the C family.

There are a lot of other differences and similarities that, if you are dealing with them, are a very specialized discussion, just say a sentence: The biggest similarity between these two languages ​​is that they are both part of the C family. And the biggest difference is that C # is a type-safe language (unlike C ++), and it can only be written by .NET applications.
-
Last edited on by admin
c# is poorly supported off windows and does not support operator overloading (critical to doing serious math programming and much cleaner to have generally). This alone makes it totally worthless to me. I need math to look like math, x = a+b not x = add(a,b) ... for big complex equations that gets unreadable in a hurry.

c# has its moments but remember what it is... its the result of the lawsuit where m$ tried to borgify java and lost, so they branched it and renamed it (poorly, it should have been called J-flat)
...does not support operator overloading

C# supports operator overloading since the beginning, you probably confuse it with Java.

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/overloadable-operators
...This is a spam OP post... note that the OP didn't even pretend to actually ask a question. Whatever, it doesn't really matter.

But here's my two cents on C# and C++:

C++ is of course much more powerful, but I find C# much quicker to make a variety of programs in than C++, and much easier to spot bugs in. For example, you want a stack trace? In C# it's just Environment.StackTrace. In C++, there is no standard solution, you either need to use a specific compiler, and write your own wrappers, or use an external library like boost or StackWalker.

C++ has so much "gotcha" behavior when you get into the nitty-gritty details. For example, the fact that short-circuiting does not happen when you use an overloaded && or || operation. There's other examples, but in general it's just not intuitive behavior at times. The concept of "undefined behavior" means that your program will never be completely secure unless you provide wrappers around places that may expose undefined behavior, such as preventing integer overflow with checks before you actually perform the addition or multiplication. C#, on the other hand, has a simple "checked" keyword that will throw an exception on overflow, instead of causing your whole program to become illegal.

C# intellisense/compiler errors tend to be very clean. C++ compiler errors are the opposite. Considering that templates in C++ are turing complete, and that the syntax of C++ is just more complicated in general, IntelliSense tends to be horrible at diagnosing all the possible problems, and template compiler errors just look horrendous in C++.

And as Thomas1965 noted, C# does have operator overloading, but the degree of freedom that C++ allows in operator overloading can be more of a curse than a blessing, at times. Sure, for many aspects of C++, once you learn about them you can consciously avoid doing them, but, in a nutshell, what I'm saying is that there are so many more ways to do something wrong without knowing it in C++ than in C#.

In C#, I dislike the "using" feature when working with disposable objects. As a user of a class, I shouldn't have to know whether or not something is Disposable and I need to handle it differently, else have some sort of resource leak. This is where C++ destructors are actually really useful, although problems with C++ destructors include knowing that you shouldn't ever throw an exception inside of a destructor, another gotcha.

I also like how C# limits the use of macros.

I admit I have not done multi-platform programming C#, but I thought C# has been pretty stable with support for other platforms for a while now.

panel123 wrote:
And the biggest difference is that C # is a type-safe language (unlike C ++

What? I would say both of them can be equally non-type-safe, at times. The abusing of Object base class in C# is just as bad as abusing void* casting in C++. C++ is more type safe in that you can rely on static templates instead of weird inheritance runtime checks.
Last edited on
Topic archived. No new replies allowed.