1.) value types cannot be assigned null because, by definition, they can't contain references,To declare variables that can store null you use the nullable modifier, ?. int? count = null; Assigning null to value types is especially attractive in database programming.
2.)In C# 2.0, all the numeric primitive types include a static tryParse() method.similar to the Parse() method,but if fails, the tryParse() method returns false not a exception
3.)In C# 2.0, it is possible to use the default() operator to determine the default value of a data type,such as default(int) return 0
4.)In C# 2.0, System.Array.Resize equal vb's Redim
5.)Static class introduced in C# 2.0, public static class name
6.) const:
Just as with const local variables, a const field contains a compile-time-determined value that cannot be changed at runtime.
readonly:
the readonly modifier is available only for fields (not for local variables) and it declares that the field value is modifiable only from inside the constructor or directly during declaration.
Unlike constant fields, readonly fields can vary from one instance to the next. In fact, a readonly field's value can change from its value during declaration to a new value within the constructor. Furthermore, readonly fields occur as either instance or static fields.
Another key distinction is that you can assign the value of a readonly field at execution time rather than just at compile time.
Using readonly with an array does not freeze the contents of the array. It freezes the number of elements in the array because it is not possible to reassign the readonly field to a new instance.
7.)Properties:
In C# 2.0, support was added for placing an access modifier on either the get or the set portion of theim property plementation (not on both), By using private on the setter, the property appears as read-only to classes other than class which the property belong to
Properties and Method Calls Not rAllowed as ef or out Parameter Values,because there are no memory address to pass
8.)Iterators:
public class Bruteforce<T> : IEnumerable<T>{
public System.Collections.IEnumerator<T> GetEnumerator(){
...
yield return item;
...
}
//multi iterators within a class (when foreach in ....GetReverseEnumerator())
public IEnumerable<T> GetReverseEnumerator()
{
yield return Second;
yield return First;
}
}
Canceling Further Iteration: yield break;similar to placing a return statement at the top of a function
9.)2.0,delegate such as GreaterThanHandler,instance as GreaterThan,pass as param you can directly use GreaterThan,
prior to 2.0 you should new GreaterThanHandler(GreaterThan)
10.)Anonymous Methods:
GreaterThanHandler greaterThan;
greaterThan =
delegate(int first, int second)
{
return (first < second);
};
BubbleSort(items, greaterThan);
or
BubbleSort(items,
delegate(int first, int second)
{
return (first < second);
}
);
you cannot use the typeof() operator on an anonymous method, and calling GetType() is possible only after assigning the anonymous method to a delegate variable.
Variables that programmers declare outside an anonymous method and access within the implementation are outer variables.