8.03.2012

CSharp Difference FAQs-1


1.Difference between C# 3.5 and C# 4.0
S.No
C# 3.5
C# 4.0
1
C# 3.5 does not support dynamic programming.
C# 4.0 supports dynamic programming through dynamic objects.
2
The dynamic keyword is not recognized in C# 3.5.
In C# 4.0, dynamic keyword is associated with objects to represent them as dynamic objects.
3
Dynamic variables cannot be created in C# 3.5.
C# 4.0 allows creation of dynamic variables.
4
In C# 3.5, method parameters cannot be specified with default values. C# 3.5 does not support optional parameters.
In C# 4.0, the method parameters can be specified with default values using optional parameters.
5
In C# 3.5, method parameters have to be specified in the same order as in method declaration in the method call. C# 3.5 does not provide named parameters.
C# 4.0 provides named parameters to represent the values of method parameters without following the order of declaration.
6
In C# 3.5, usage of ref keyword is mandatory while executing methods which are supplied by the COM interfaces.
In C# 4.0, usage of ref keyword is optional while executing methods which are supplied by the COM interfaces.
7
The COM object’s indexed properties are not recognized in C# 3.5.
The COM object’s indexed properties are recognized in C# 4.0.
8
Co-variance and contra-variance are not supported in Generics of C# 3.5.
C# 4.0 enhances Generics by introducing co-variance and contra-variance.
2.Difference between C# and VB.NET

S.No
C#
VB.NET
1
In C#, variables are declared using declarators.
In VB.NET, the variables are declared using keywords such as private, protected, friend, public, static, shared and Dim.
2
In C#, an object can only be created using new.
In VB.NET, an object can be created using new and CreateObject().
3
In C#, void is specified as the return type when a method does not return a value.
In VB.NET, Sub is used in method declaration to indicate that the method does not return any value.
4
In C#, no keyword is required to indicate an overloaded method.
In VB.NET, Overloads keyword is used to indicate an overloaded method.
5
The current object is referred using this pointer in C#.
The current object is referred as me in VB.NET.
6
Non virtual call cannot be made in C#.
To make a non-virtual call to the current object’s virtual method, MyClass is used in VB.NET.
7
Compound data type is declared in C# using class, struct and interface.
Compound data type is declared in VB.NET using Structure.
8
In C#, constructors are used to initialize an object.
In VB.NET, Sub New() is used to initialize the newly created object.
9
Object cleanup can be explicitly done by destructor in C#.
Object cleanup can be done by using Finalize method in VB.NET.
10
In C#, an object is subject to asynchronous modification using volatile keyword.
In VB.NET, an object cannot be modified in an asynchronous way.
11
In C#, all the variables have to be declared before being used.
In VB.NET, variables can be forced for explicit declaration using Option Explicit.
12
In C#, default property is defined by using indexers.
In VB.NET, default property is defined using Default.
13
In C#, base class can be referred using the keyword ‘base’.
In VB.NET, base class can be referred using the keyword ‘MyBase’.
14
Abstract class of C# can only be inherited and not instantiated.
MustInherit keyword of VB.NET is used to denote that a class can only be inherited and not instantiated.
15
Sealed keyword of C# is used to denote that a class cannot be inherited.
NotInheritable keyword of VB.NET denotes that the class cannot involve in inheritance.
16
Division can be performed in C# using / operator.
Division can be performed in VB.NET using \ operator.
17
Remainder of division can be retrieved using mod operator of C#.
Remainder of division can be retrieved using %.
18
C# does not have exponentiation operator.
In VB.NET, exponentiation can be performed using ^ operator.
19
C# has Bitwise operators namely &,| and ^.
Bitwise operators in VB.NET are And, Or, Xor.
20
Object reference variables can be compared using == operator in C#.
Object reference variables can be compared using Is operator in VB.NET.
21
The short ciruit operators in C# are && (Boolean AND) and || (Boolean OR).
The short circuit operators in VB.NET are AndAlso (Boolean AND) and OrElse (Boolean OR).
3.Difference between C# and C++

S.No
C#
C++
1
C# is a high level language that is component oriented.
C++ is a low level and indeed platform neutral programming language.
2
When compiled, C# code is converted into Intermediate language code. This intermediate language code is converted into executable code through the process called Just-In-Time compilation.
When compiled, C++ code is converted into assembly language code.
3
In C#, memory management is automatically handled by garbage collector.
In C++, the memory that is allocated in the heap dynamically has to be explicitly deleted.
4
In C# Switch Statement, the test variable can be a string.
In C++ Switch Statement, the test variable cannot be a string.
5
In C# switch statement, when break statement is not given, the fall through will not happen to the next case statement if the current case statement has any code.
In C++ switch statement, when break statement is not given, the fall through will happen to the next case statement even if the current case statement has any code.
6
In addition to for, while and do..while, C# has another flow control statement called for each.
C++ does not contain for each statement.
7
C# struts can contain only value types. The struts is sealed and it cannot have a default no-argument constructor.
C++ struts behave like classes except that the default access is public instead of private.
8
In C#, delegates, events and properties can also be specified as class members.
In C++, only variables, constructors, functions, operator overloads and destructors can be class members. Delegates, events and properties cannot be specified as class members.
9
In C#, the end of the class definition has a closing brace alone.
In C++, the end of the class definition has a closing brace followed by a semicolon.
10
The access modifiers in C# are public, private, protected, internal and protected internal.
The access modifiers in C++ are public, private, protected. C++ does not have internal and protected internal access modifiers.
11
C# has finally block in exception handling mechanism. The code statements in the finally block will be executed once irrespective of exception occurrence.
C++ does not have finally block in exception handling mechanism.
12
The exception in C# can only throw a class that is derived from the System.Exception class.
The exception in C++ can throw any class.
13
C# does not have the concept of function pointers. C# has a similar concept called Delegates.
C++ has the concept of function pointers.

No comments:

Post a Comment