Geeks With Blogs
Blog Moved to Blog Moved to
Kenny Kerr wrote an article for the MSDN entitled C++: The Most Powerful Language for .NET Framework Programming which is definitely an interesting read.  The point of the article is to compare and contrast C++/CLI and its functionality to that of C#.
This article focuses on the changes in C++ from the C++ with Managed extensions which came with Visual Studio 2003 that make C++/CLI a much more viable alternative than in the past.  When going between Managed C++ and C#, your code could look drastically different.  C++/CLI has closed the gap in functionality and keywords drastically since then.
Kenny states it wasn't his intent to get people to switch from C# to C++, it was more on the focus on those already in C++ who want the productivity features of C#.
The chart at the bottom is the real interesting piece from this article which contrasts C++/CLI and C# and gives an example of each.  I added some of my own as well such as enum defintions as well. 
Description C++/CLI C#
Allocate reference type ReferenceType^ h = gcnew ReferenceType; ReferenceType h = new ReferenceType();
Allocate value type ValueType v(3, 4); ValueType v = new ValueType(3, 4);
Reference type, stack semantics ReferenceType h; N/A
Calling Dispose method ReferenceType^ h = gcnew ReferenceType;
delete h;
ReferenceType h = new ReferenceType();
Implementing Dispose method ~TypeName() {} void IDisposable.Dispose() {}
Implementing Finalize method !TypeName() {} ~TypeName() {}
Null reference checks if(myObj == nullptr) if(myObj == null)
Iterating through collection with for each for each(String^ in myCollection) foreach(string in myCollection)
Boxing int^ h = 123; object h = 123;
Unboxing int^ h = 123;
int c = *hi;
object h = 123;
int i = (int) h;
Reference type definition ref class ReferenceType {};
ref struct ReferenceType {};
class ReferenceType {}
Value type definition value struct ValueType {};
struct ValueType {}
class ReferenceType {}
Enum type definition enum class EnumType {}; enum EnumType{}
Using Enums EnumType type = EnumType::FirstValue EnumType type = EnumType.FirstValue
Using properties h.Prop = 123;
int v = h.Prop;
h.Prop = 123;
int v = h.Prop;
Property definition property String^ Name
     String^ get()
          return m_value;
     void set(String^ value)
          m_value = value;
string Name
          return m_name;
          m_name = value;
 So, as you can see, there are a few slight semantical differences between the two languages, but the overall functionality is pretty similar if not identical.  C++/CLI has made some real strides in becoming more usable as a day to day language instead of just being one concentrated on performance only. 
Of course many people will stick with C# because of the fact that it is a more pure .NET language.  With C++/CLI, it takes no effort to mix and match code from unamanged to managed whereas you have to work at it to do the same in C#.  Either way, I really do like the improvements made to C++.
Posted on Monday, June 5, 2006 10:38 AM .NET , C# | Back to top

Comments on this post: The Most Powerful Language for .NET Programming

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Matthew Podwysocki | Powered by: