I'm a C# programmer for a few months, and lately I've been considering learning C++.
So my question is, is there anything C++ can do that C# can't do?
I know about the manual memory management in C++, but as long as I don't program operating systems or extremely heavy memory applications, I shouldn't worry about that too much (becuase I heard .NET handles automatic memory management very well).
But, can I program in C# everything that I can in C#? I also mean things like DLL injection, Registry Editing, Drivers and things like that.
Is C# considered as powerful as C++? If not, what can't C# do that C++ can?
C# and C++ are languages. It's somewhat elusive to define what a language "can" and "can't" do. One example of a thing that C++ can do and C# can't, is free the memory of an heap allocated object at will, without freeing other unused objects as well. But it's a thing that won't matter most of the time. (You can use Marshal.AllocHGlobal
and Marshal.FreeHGlobal
to allocate and deallocate memory like in C.)
The main reason why C++ can be used to write things like Windows drivers is because this is what Windows supports and facilitates. If one day Microsoft decided to support only C# and ditch C++, we'd be here saying that C# can do something that C++ can't (even if the languages magically remained as they are now, by then). Most likely it won't, and rightly so, because C++ is better fit for systems programming than C#. But hopefully you get the point.
Essentially, it's not a matter of the languages themselves, but their implementations, their tools and the world around them. For example, you can easily write an operating system in C#. Why? Because there's a proper tool for it. You can also write for embedded systems with non-real-time requirements. It has nothing to do with the language, again, it's because there's a tool for it.
That being said, do learn C++. Regardless of how it compares with other languages, it's absolutely useful.
C# is a slightly higher level language that C++. Its requirement of a managed runtime environment means that you wont be able to write an operating system, or even a device driver, in it. This sort of area is typically known as systems programming
However, there is a Microsoft research project currently underway into creating a systems program version of C#. It's headed up by Joe Duffy, the Windows threading guru, and if the rumors on the web are to be believed it will be called M#. Joe has posted some information about his progress on his blog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With