• Implicit local variables and Arrays
VaR I = 5;
VaR A = new [] {0, 1, 2 };
• Object Initial Value Setting item
Private class cat
{
Public int age {Get; set ;}
Public string name {Get; set ;}
}
Static void methoda ()
{
Cat cat = new cat {age = 10, name = "Sylvester" };{ g, y };
}
• Set initial values
List <int> digits = new list <int> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
List & lt; Int & gt; digits2 = new list & lt; Int & gt; {0 + 1, 12% 3, makeint ()};
• Automatically implemented attributes
Class lightweightcustomer
{
Public double totalpurchases {Get; set ;}
Public string name {Get; private set;} // read-only
Public int customerid {Get; private set;} // read-only
}
• Anonymous type
VaR v = new {amount = 108, message = "hello "};
• Extension Method
Namespace extensionmethods
{
Public static class myextensions
{
Public static int wordcount (this string Str)
{
Return Str. Split (New char [] {'', '.', '? '},
Stringsplitoptions. removeemptyentries). length;
}
}
}
Using extensionmethods;
String S = "Hello extension methods ";
Int I = S. wordcount ();
• Division method definition
// Definition in file1.cs
Partial void onnamechanged ();
// Implementation in file2.cs
Partial void onnamechanged ()
{
// Method body // et OD body
}
• Lambda expressions
Lambda expressions
VaR Results = people. Where (P => P. lastname = "white ");
Delegate int del (int I );
Del mydelegate = x => X * X;
Int J = mydelegate (5); // J = 25
Lambda statements
Delegate void testdelegate (string S );
... ...
Testdelegate MYDEL = n => {string S = N + "" + "world"; console. writeline (s );};
MYDEL ("hello ");