What Uma tried to explain is called
type inference, introduced in C# v.3. See:
http://en.wikipedia.org/wiki/Type_inference[
^],
http://msdn.microsoft.com/en-us/library/ms364047%28v=vs.80%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/ms364047%28v=vs.80%29.aspx#cs3spec_topic2[
^].
I found pretty nice short explanation here:
http://geekswithblogs.net/sdorman/archive/2007/04/06/111034.aspx[
^].
Pay attention of type inferred from a constructor, this is a most important case:
var myInstance = new MyClass.Create();
MyClass. myInstance = new MyClass.Create();
Type can be inferred from container in
foreach
, type of parameters inferred from the type of delegate:
myTextBox.KeyPress = (sender, eventArgs) => {
}
This is another important case of inference, practically the most important one.
—SA