Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


To begin, C# or C++?

Posted on 2002-03-23
Medium Priority
Last Modified: 2010-04-17
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!  
Question by:kennon2000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 22

Expert Comment

ID: 6890778
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


LVL 22

Expert Comment

ID: 6890782
Pure C# example:

public void MyFunc(ref iRes)
   iRes = 10;

(note the difference)


Author Comment

ID: 6891104
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?
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.


Expert Comment

ID: 6891764
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++.
LVL 22

Accepted Solution

CJ_S earned 600 total points
ID: 6892320
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 :-)


LVL 22

Expert Comment

ID: 6892323
>> This IL is compiled whenever the program is started or when that
part of code is needed

called JITting (Just In Time)

Author Comment

ID: 6893086
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.
LVL 22

Expert Comment

ID: 6893405
:-) Glad to help!

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question