tags:

views:

390

answers:

5

In a progression of languages, I have been learning C and C++. Now I would like to learn C#. I know there are some drastic differences between them - such as the removal of pointers and garbage collection. However, I don't know many of the differences between the two.

What are the major differences that a C++ programmer would need to know when moving to C#? (For example, what can I use instead of STL, syntactic differences between them, or anything else that might be considered important.)

+8  A: 

C# for C++ Developers is a great place to start. It is a table that lists the most important comparisons between the two languages.

Once you have explored some of these differences, you might choose a self-contained project you have written in the past in C++, and re-write it in C#. In your first pass, you will probably just end up translating directly across, using the same design and algorithms. As you become more comfortable with C#, you will recognize ways to take advantage of language features only available in C#, as well as the incredibly versatile .NET Framework.

Jeff Hillman
definately read a good book about .net so you can take full value of the framework. I have taken the same step youre about to take and i suggest reading ProC# 2008 by Andrew Troelsen. Maybe there is already a new Edition of that book.
Johannes Rudolph
+2  A: 

I think it's important to note that pointers weren't really removed from C#, but that they still exist, they are everywhere, and they are called references.

Greg Hewgill
I know they are still there - computers can't work without 'em. What really seems to have happened is that the difference between an object and a pointer to that object is hidden. Mostly.
Cristián Romo
Classic pointers are direct memory addresses of the location of particular object or vpiece of data. The CLR can reorder the objects in memory to compact the heap; thus a reference to an object does not necessarily reflect its position in the memory.
Franci Penov
And you can use pointers in C#, the code just has to be marked unsafe. http://msdn.microsoft.com/en-us/library/t2yzs44b.aspx
Jason Jackson
+1  A: 

Look at the Generic collections and LINQ (all the related technology to LINQ) for STL like functionality.

The number one thing to note is that ~/Destructor is c++ is nothing like the ~/finalizer in c# -- See IDisposable/using.

dpp
A: 

There was a similar question that has lots of pointers (pun inteded :-)) and resources about the differences between C++ and C# and what to pay attention when learning transitioning - Linux/C++ programmer to Windows/C# programmer.

Franci Penov
+1  A: 

Charles Petzold has a .NET Book Zero that is designed specifically for the C/C++ Windows programmer who wants to learn C# and .NET. It is a free PDF download from his site. All of the source code used in the book is available as a separate Zip-file download.

orcmid