Last night, I attended the local C# SIG. I make sure I attend this SIG on a monthly basis. The topic was on the new features C# 2010. Here are my notes.
static dynamic type
- bypass type checking
- offload until runtime
- implicit conversion
- Examples
- dynamic d = 7; // implicit conversion
- int i = d; // Since d is int, we can assign it to an integer
- d = "Hello world" // Now, d is a string
- int i = d; // this will not work (cannot place a string in int)
- Can take on type of object, which means that d can call methods from an object such as:
- dynamic d = o1.m()
- but, this means that we can reassign d to another object that happens to have the same method name. On a personal note, I can see this leading to bad code. See this example:
- dynamic d = obj;
- d.method();
- dynamic d = obj1;
- d.method();
- This was feature was because of the inclusion of F# and IronRuby in the Microsoft tool kit.
- yhere was a discussion if datatypes are tied to memory space or method space. It was decided that datatypes are tied to method space unless they are declared as public.
covariance/contravariant
- converting specific to generic (string to object)
- utilize out keyword
- enable implicit reference conversion for array, delegates, interfaces (generic type argument)
- These are mostly used for generic interfaces
contravariant
- converting generic to specific (ex: generic to string)
- utilize in keyword
optional parameters
- lead to named parameters
- public void M(int x, int y=5, int z=7, int ii); // ii is the optional parameter
- M(1,Z:3);
- optional parameters after required arguments
COM Interop
- PIA:.Net assembly generated from COM interface
- No PIA deployment at runtime
- Compiler will incorporate necessary features into assembly
- ByRef implicitly defined
Call Hierarchy
- enables tp explore all possible execution paths
- shows 'Calls To'
- shows 'Call From'
Tuples
- fixed-size collection of different typed data.
- strong typing for each element
- System.Tuple
- var BigTuple = Tuple.Create("Value",1,2,3,5.7, "Test",7)
- var Element1 = BigTuple.Item1;
- Tuple<string, int> t = new Tuple<string, int>("Hello", 4)
- string s = t.item1;
- int i = t.item2;