|
|
What is the difference between var and dynamic types in C# 4.0?
|
|
var gets processed in the compile time itself and shows any error during compile time itself.
dynamic gets processed in the runtime only and in case of errors it is hidden until runtime.
dynamic was introduced as part of the DLR (Dynamic Language Runtime) in .Net.
Example: dynamic d = new MyClass(); d.InexistingMethod();
Eventhough the method "InexistingMethod" is not there - it will get compiled and thrown exception in runtime.
|
|
|
|
You can also find related Interview Question to What is the difference between var and dynamic types in C# 4.0? below:
|
|
|
|
Value type & reference types difference? Example from .NET. Integer & struct are value types or reference types in .NET?
supports two kinds of value types:
Ãâ÷ Builtin
value types
The .NET Framework defines builtin
value types, such as System.Int32 and
System.Boolean, which correspond and are identical to primitive data types
used by programming languages.
Ãâ÷ Userdefined
value types
Your language will provide ways to define your own value types, which derive from System.ValueType. If you want to define a type representing a value that is small, such as a complex number (using two floatingpoint numbers),
you might choose to define it as a value type because you can pass the value type efficiently by value. If the type you are defining would be more efficiently passed by reference, you should define it as a class instead.
Variables of reference types, referred to as objects, store references to the actual data. This following are the reference types:
Ãâ÷ class
Ãâ÷ interface
Ãâ÷ delegate
This following are the builtin
reference types:
Ãâ÷ object (More...)