Bas Bossink
August 2011
| Time | VS | Framework | C# | Theme |
|---|---|---|---|---|
| 2005 | 2005 | 2.0 | 2.0 | Generics |
| 2006 | 2005 | 3.0 | 2.0 | WPF, WCF, WF |
| 2008 | 2008 | 3.5 | 3.0 | LINQ |
| 2009 | 2008 SP1 | 3.5 SP1 | 3.0 | |
| 2010 | 2010 | 4.0 | 4.0 | Dynamic, Parallel |
var ≠ objectDictionary<string,Func<string,double>> fred =
new Dictionary<string, Func<string,double>>();
↓
var fred = new Dictionary<string, Func<string,double>>();
public class Flinstone {
private string m_Name;
public string Name {
get { return m_Name; }
set { m_Name = value; }
}
}
↓
public class Flinstone {
public string Name { get; set; }
}
var fred = new List<int>() { 37, 42, 53 };
var fred = new Flinstone { Name = "Fred" };
IEnumerable<T>public static string YabaDabaDo(this Flinstone fred) {
...
}
...
var noise = fred.YabaDabaDo();
var fred = new { Name = "Fred", Friend="Barney" };
var flinstones = bedrockCitizins.Find(
delegate(string c) {
return c.Lastname.Equals("Flinstone");
});
↓
var flinstones = bedrockCitizins.Find(
c => c.Lastname.Equals("Flinstone"));
{objects, xml, ... }IEnumerable<T>,IQuereable<T> in System.LinqIQueryable<T>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var flinstones = from citizen in bedrockCitizens
where citizen.Name.Equals("Flinestone")
select citizen.Name;
var pythagoreanTriples = from a in Enumerable.Range(1, 25)
from b in Enumerable.Range(a, 25 - a)
from c in Enumerable.Range(b, 25 - b)
where a * a + b * b == c * c
select Tuple.Create(a, b, c);
Expression'sFunc<int, int> twiceD = x => x * 2;
Expression<Func<int, int>> twiceE = x => x * 2;
// Definition in file1.cs
partial void onNameChanged();
// Implementation in file2.cs
partial void onNameChanged()
{
// method body
}
dynamic almost everywhere you would use a type namemethod_missing meta-programming// Before the introduction of dynamic.
((Excel.Range)excelApp.Cells[1, 1]).Value2 = "Name";
Excel.Range range2008 = (Excel.Range)excelApp.Cells[1, 1];
// With dynamic
excelApp.Cells[1, 1].Value = "Name";
Excel.Range range2010 = excelApp.Cells[1, 1];
bool IsFlinstone(
string firstName,
string lastName) {
...
}
...
var fred = IsFlinstone(
lastName: "Rubble",
firstName: "Barney");
bool IsFlinstone(
string firstName,
string lastName = "Flinstone") {
...
}
if(IsFlinstone("Fred")) {
...
}
if(IsFlinstone("Barney", "Rubble")) {
...
}
out keyword for generic parameterspublic interface IEnumerator<out T> :
IDisposable,
IEnumerator {
T Current { get; }
bool MoveNext();
void Reset();
}
IEnumerable<String> strings = new List<String>();
IEnumerable<Object> objects = strings;
in keyword for generic parameterspublic interface IComparer<in T> {
int Compare(T x, T y);
}
void PutOutside(object o) { .... }
Action<object> action = PutOutside;
Action<Flinstone> dinoAction = action;
HashSet<T>Func<...> delegate declarationsAction<...> delegate declarationsTuple<...>ReaderWriterLockSlimBigIntegerComplexSystem.Threading.Tasks namespaceParallel.ForEach(sourceCollection,
item => Process(item));
Task<string> reportData2 =
Task.Factory.StartNew(() => GetFileData())
.ContinueWith((x) => Analyze(x.Result))
.ContinueWith((y) => Summarize(y.Result));
var pythagoreanTriples =
from a in Enumerable.Range(1, 25).AsParallel()
from b in Enumerable.Range(a, 25 - a)
from c in Enumerable.Range(b, 25 - b)
where a * a + b * b == c * c
select Tuple.Create(a, b, c);