Florian Rappl, Department of Theoretical Physics, University of Regensburg
=>
(x, y) => x * x + y
x => { return x > 0 ? -1 : (x < 0 ? 1 : 0); }
return
) can be omitted if single statementdelegate [RET] [NAME]([ARGUMENTS])
solves this problemFunc<TReturn>
Func<double, double> squ = x => x * x;
squ(2)
new { Name = "Florian", Age = 28 }
creates such an objectobject
var
)object
, unless ...var
var i = 4
will infer Int32
var pi = 3.14f
(Single
)var a = new { Name = "My name" }
(who cares!)static
) methodsthis
keywordMyClass.MyMethod(a)
a.MyMethod()
(shorter and more expressive)namespace MyExtensionMethods
{
static class ExtMethods {
public static void Dump(this string s) {
Console.WriteLine(s);
}
}
}
System.Linq
IEnumerable<T>
has LINQ methodsdouble[] a
? a.OrderBy(m => m)
int[] a
: a.Where(m => m % 2 == 0)
foreach
is more expensive than for
IEnumerable<T>
is in-memory queryIQueryable<T>
is for remote-dataint a; public int A { /* ... */ }
public int A { get; set; }
abstract
propertiesabstract
keywordMessageBox
or the Console
for debuggingDebug
or Trace
DEBUG
definition in debug-modeDebug.WriteLine()
Florian Rappl, MVP Visual C#