Wednesday, July 14, 2010

Few imp points in C++ and C#

1)Memory Management


The other difference is that there is no equivalent to C++ delete operator in C#. Instead, with C#, the .Net garbage collector periodically comes in and scans through the refrences in your code in order to identify which areas of the heap are currently in use by our program. It is then automatically able to remove all the objects that are no longer in use. This technique effectively saves you from having to free up nay memory yourself on the heap.

2)New control flow statement- for each

C# provides an additional flow control statement, for each. For each loops across all items in array or collection without requiring explicit specification of the indices.
Syntax:

Foreach(double someElement in MyArray)
{
Console.WriteLine(someElement);
}

3) Classes

Classes in C# follow much the same principles as in C++, though there are a few differences in both features and syntax.

Class MyClass : MyBaseClass
{
Private string SomeFiels;
Public in SomeMethod()
{
Return;
}

Classes defined in C# using what at first sight looks like much the same syntax as in C++, but there are numerous differences:

There is no access modifier on the name of the base class. Inheritance is always public.

A class can only be derived from one base class. If no base class is explicitly specified, then the class will automatically be derived from System.Object, which will give the class all the functionality of System.Object, the most commnly used of which is ToString().

In C++, the only types of class members are variables, functions, constructors, destructors and operator overloads, C# also permits delegates, events and properties.

The access modifiers public, private and protected have the same meaning as in C++ but there are two additional access modifiers available:


i. Internal
ii. Protected internal

C++ requires a semicolon after the closing brace at the end of a class definition. This is not required in C#.

No comments:

Post a Comment