Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Sunday, May 1, 2011

What is the difference between VB.NET and C# ?


Well this is the most debatable issue in .NET community and people treat there languages like religion. Its a subjective matter which language is best. Some like VB.NET’s natural style and some like professional and terse C# syntaxes. Both use the same framework and speed is also very much equivalents. But still let’s list down some major differences between them :-

Advantages VB.NET :-
√ Has support for optional parameters which makes COM interoperability much easy.
√ With Option Strict off late binding is supported.Legacy VB functionalities can be used by using Microsoft.VisualBasic namespace.
√ Has the WITH construct which is not in C#.
√ The VB.NET part of Visual Studio .NET compiles your code in the background. While this is considered an advantage for small projects, people creating very large projects have found that the IDE slows down considerably as the project gets larger.
Advantages of C#
√ XML documentation is generated from source code but this is now been incorporated in Whidbey.
√ Operator overloading which is not in current VB.NET but is been introduced in Whidbey.
√ Use of this statement makes unmanaged resource disposal simple.
√ Access to Unsafe code. This allows pointer arithmetic etc, and can improve performance in some situations. However, it is not to be used lightly, as a lot of the normal safety of C# is lost (as the name implies).This is the major difference that you can access unmanaged code in C# and not in VB.NET

What is concept of Boxing and Unboxing ?


Boxing permits any value type to be implicitly converted to type object or to any interface type implemented by value type. Boxing is a process in which object instances are created and copy values in to that instance.

Unboxing is vice versa of boxing operation where the value is copied from the instance in to appropriate storage location.

Below is sample code of boxing and unboxing where integer data type is converted in to object
and then vice versa.

Dim x As Integer
Dim y As Object
x = 10
‘ boxing process
y = x
112
‘ unboxing process
x = y

What are Value types and Reference types ?


Value types directly contain their data which are either allocated on the stack or allocated in-line in a structure.
Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types.
Variables that are value types each have their own copy of the data, and therefore operations on one variable do not affect other variables. Variables that are reference types can refer to the same object; therefore, operations on one variable can affect the same object referred to by another variable. All types derive from the  ystem.Object base type.

What are different types of JIT ?


JIT compiler is a part of the runtime execution environment.
In Microsoft .NET there are three types of JIT compilers:

Pre-JIT :- Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.
Econo-JIT :- Econo-JIT compiles only those methods that are called at runtime However, these compiled methods are removed when they are not required.
Normal-JIT :- Normal-JIT compiles only those methods that are called at runtime .
 These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.

What is reflection?


All .NET assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as “Reflection”.System. Reflection can be used to browse through the metadata information. Using reflection you can also dynamically invoke methods using  ystem.Type.Invokemember.

Can we force garbage collector to run ?


System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arises.

What is garbage collection?


Garbage collection is a CLR feature which automatically manages memory. Programmers forget to release the objects while coding ..... Laziness (Remember in VB6 where one of the good practices is to set object to nothing). CLR automatically releases objects when they are no longer in use and refernced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function. Therefore, we should not put code into a class destructor to release resources.