Differences Between C# and C++: Dr. Catherine Stringfellow Dr. Stewart Carpenter
Differences Between C# and C++: Dr. Catherine Stringfellow Dr. Stewart Carpenter
C# and C++
Constants
Math.PI = 3.1415926535…
Type Promotion
Implicit Conversion
Coercion of arguments to a higher type when
passed to methods or in mixed-type expressions;
Explicit Conversion
Done with cast or class Convert in namespace
System
Cast Example: int result = Square ( (int ) y );
Value and Reference Types
Value types
Contain data of the specified type
Built in types (int, float, double,…)
Programmer created - structs and
enumerations
Reference types
Contain an address
Built-in (array, object and string)
Programmer created – Classes, Interfaces
and Delegates
Passing Arguments by Value vs.
by Reference
Value types are passed by value and reference
types are passed by reference by default
Jagged Arrays
An array of arrays of different lengths
// declaration of rectangular array
int[,] array1 = new int[5,10];
// property Hour
public int Hour
{
get
{ return hour; }
set
{ hour = ( ( value >= 0 && value < 24 ) ? value : 0 ); }
}