To begin, C# or C++?

Hi Experts,

I want to learn C++ or C#.  What should I choose?
I like .Net Framework, but will C++ developer eventually turn to C# if C# really portable and effective?  I am afraid I cannot edit old C++ program, is there any method to translate C++ to C#?

Thanks a lot for help!  
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

CJ_SConnect With a Mentor Commented:
MFC and ATL are relatively easy to learn, but of course that depends on how the learner can get a grasp on it. For me it took me about a year (I was 14 when I started with MFC).

Sure C/C++ applications have been around for a VERY long time, and yes it will stay alive for a very long time, and also yes for that companies won't give up their applications right away. And why should they? C# is a totally new language. So you can say "No i want to keep up with nowadays proven technologies like C++" or you can say "hey I want to be a guru on this new language". I cannot tell you why you should pick any of the languages, it will be YOUR choice. I think that in the future there will be a lot of C# jobs, but don't pin me on that :-)

>> The greatest concern is that most company still keep
>> their 10-year-old C++ programs, if I only know
>> C#, I have no way to amend these program.
The difference is as big as between VB and C++, except that C# can use C++ code. So the above line doesn't really matter IMHO.

>> want to know does the unsafe function of C# means its
>> compiler accept C++ program? If not, how is the
>> compatibility?
I'm not quite sure what you mean. the unsafe keyword ensures that C++ is being used. So you can use pointers, references and all the other stuff that you would've used when writing C++. The compiler accepts C++ code, not a C++ program. There's also another thing you should know. In languages like VB and C++ you are used to the compiler. The code you write is being converted to native WIN32 code (assuming windows platform). With C# (and other languages  built on top of the .Net platform) the code is being converted to IL-code (Intermediate language). This IL is compiled whenever the program is started or when that part of code is needed. So compiling is like: code -> IL -> native (in memory until program ends or garbage collector runs). It is possible to compile to native code directly too (thought I'd mention that :-)...). However, I am not quite sure whether unsafe code actually compiles to IL or native code... I suppose it is IL but I am not sure.

Last thing I'd like to mention. You seem to not want C# but C++. If you still feel like that then go for that language. Choose the language that you fit in :-)


C++ and C# are two different languages although they do have things in common and it is possible to use unsafe code in C# (meaning C++). C# requires a totally new way of thinking, and will become a great language in the future. The advantage of a new programming language like C# is that you can work with it from the start and get the whole thing into your mind. While C++ has a very long history AND has already been proven.

We cannot decide for you, we can only help you make a decision.

C++ to C# is possible (as explained) by using unsafe code, but it won't give you the advantages of the .Net platform (like garbage collection).
Normal (C++)
public void MyFunc(int *iRes)
   *iRes = 10;

Unsafe example (C#):
unsafe public void MyFunc(int *iRes)
   *iRes = 10;

As you can see it is very similar. The * is the pointer which is NOT present in C# itself (instead you use the in, out and ref keywords). The difference between the languages is huge, but they are similar.

My personal favor is C# at the moment, also because of the unsafe functionality.

Decide for yourself


Pure C# example:

public void MyFunc(ref iRes)
   iRes = 10;

(note the difference)

Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

kennon2000Author Commented:
I know more about C# than C++.  It seem MFC and ATL used in C++ need much more time to learn.  .Net Framework seem much more structuralized and well managed.  Am I right?
The greatest concern is that most company still keep their 10-year-old C++ programs, if I only know C#, I have no way to amend these program.
Thanks to CJ.  I want to know does the unsafe function of C# means its compiler accept C++ program?  If not, how is the compatibility?
If you really want to use .NET, then C# is probably useful as its libraries are tailored to that framework.  However, there are a few important things that detract from C#:

1 - There's  far more C and C++ code out there.
2 - .NET is a limited framework (granted it's big, but limited).  For general work, C# may not be as useful as C++.
3 - C# doesn't have the maturity of C++.  C++ has had time to build a really good set of libraries and features.  C# currently has what Microsoft thinks is a good set of libraries.
4 - C# is not a major evolutionary step in programming languages.  It definitely belongs to the same era as Java and other C++ work alikes.  You're not going to have programs that are easier to write with less bugs.  You might want to look at some newer types of languages, such as high-level languages (Python, Perl, etc.) or functional languages (Lisp, O'Caml, etc).  Ask yourself if you really want another C++ derivative or something new.

Personally, I have no use for .NET, and there's nothing else in C# that's caught my attention, so my vote is on C++.
>> This IL is compiled whenever the program is started or when that
part of code is needed

called JITting (Just In Time)
kennon2000Author Commented:
Thanks for CJ and other experts.  You really given me good comment.
I was impressed by CJ's comment: So you can say "No i want to keep up with nowadays proven technologies
like C++" or you can say "hey I want to be a guru on this new language".
That reminded me any new technique must has the risk of being not popular and one should have the brave to try.
I have actually started learning C# a few days before.  It seem that C# like Java more than C/C++(although I know little about C/C++), especially the reference type, string and garbage collector..etc.  If I have time, I will have a look at C++ while keeping C# as the main target.
:-) Glad to help!
All Courses

From novice to tech pro — start learning today.