history of c#

48
History of C# Andreas Schlapsi / @aschlapsi

Upload: aschlapsi

Post on 16-Jul-2015

95 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: History of C#

History of C#Andreas Schlapsi / @aschlapsi

Page 2: History of C#

Andreas Schlapsi ( )@aschlapsiC# since 2002

Page 3: History of C#

January 2002Subversion was still replacing CVSEuro banknotes and coins become legal tender in 12 member statesof the EU

Page 4: History of C#

January 2002

Page 5: History of C#

January 2002Microsoft releases the first version of the .NET framework with its new

language C#

Page 6: History of C#

C# 1.0 - Key FeaturesManaged Code (.NET)

IL Code (Intermediate Language)Common Language Runtime (Visual Basic.NET, J#, F#, ...)Base Class LibraryGarbage Collector

Page 7: History of C#

C# 1.0 - Key FeaturesOOP (classes)like Javano multiple inheritance

Page 8: History of C#

C# 1.0 - Key FeaturesProperties

public class ExampleClass{ private int _number;

public int Number { get { return _number; } set { _number = value; } }}

Page 9: History of C#

C# 1.0 - Key FeaturesDelegates and Events

Delegate: data structure that refers to either a static method, or anobject and an instance method of its class

Page 10: History of C#

C# 1.0 - Key FeaturesDelegates and Events

public delegate int ChangeInt(int x);

public class ExampleClass{ public static int DoubleIt(int n) { return n * 2; }

public void DoSomething() { ChangeInt myDelegate = new ChangeInt(DoubleIt); Console.WriteLine("{0}", myDelegate(5)); }}

Page 11: History of C#

C# 1.0 - Demo: Counter1

Page 12: History of C#

November 2005C# 2.0

Page 13: History of C#

C# 2.0 - Key FeaturesGenerics

public class ExampleClass{ public void Before() { ArrayList list = new ArrayList(); list.Add(42); int x = 2 + (int)list[0]; }

public void InCSharp2() { List<int> list = new List<int>(); list.Add(42); int x = 2 + list[0]; }}

Page 14: History of C#

C# 2.0 - Key FeaturesAnonymous Methods

public delegate int ChangeInt(int x);

public class ExampleClass{ public void DoSomething() { ChangeInt myDelegate = new ChangeInt( delegate(int x) { return x * 2; } ); Console.WriteLine("{0}", myDelegate(5)); }}

Page 15: History of C#

C# 2.0 - Key FeaturesNullable Types

Reference Typesreference to object on heapcan be null

Value Typesobject on stack or embeddedcan not be null

Page 16: History of C#

C# 2.0 - Key FeaturesNullable Types

public class ExampleClass{ public void DoSomething() { int? nullableInt = 42; Nullable<int> int2 = null;

if (nullableInt.HasValue) { Console.WriteLine(nullableInt.Value); } }}

Page 17: History of C#

C# 2.0 - Key FeaturesIterators

public interface IEnumerable<T>{ IEnumerator<T> GetEnumerator();}

public interface IEnumerator<T> : IDisposable{ T Current { get; } void MoveNext(); void Reset();}

Page 18: History of C#

C# 2.0 - Key FeaturesIterators

public class ExampleClass{ public void DoSomething() { List<string> list = new List<string>(); list.Add("Hello"); list.Add("World"); IEnumerable<string> enumerable = list;

foreach(string str in enumerable) Console.WriteLine(str); }}

Page 19: History of C#

C# 2.0 - Key FeaturesIterators

public class ExampleClass{ public void DoSomething() { foreach(int str in Iterate()) Console.WriteLine(str); }

public IEnumerable<int> Iterate() { yield return 1; yield return 2; yield return 3; yield return 4; }}

Page 20: History of C#

C# 2.0 - Demo: Counter2

Page 21: History of C#

C# 2.0 - Demo: IteratorExample

Page 22: History of C#

November 2007C# 3.0

Page 23: History of C#

C# 3.0 - Key FeaturesLambda Expressions

public delegate int ChangeInt(int x);

public class ExampleClass{ public void DoSomething() { ChangeInt myDelegate = x => x * 2; Console.WriteLine("{0}", myDelegate(5)); }}

Page 24: History of C#

C# 3.0 - Key FeaturesExtension Methods

"Add" methods to existing types without creating a new derived type,recompiling, or otherwise modifying the original type.

Page 25: History of C#

C# 3.0 - Key FeaturesExtension Methods

namespace Extensions{ public static class StringExtensions { public static int WordCount(this string str) { return str.split(new char[] { &#39; &#39;, &#39;.&#39;, &#39;?&#39; }, StringSplitOptions.RemoveEmptyEntries).Length; } }}

Page 26: History of C#

C# 3.0 - Key FeaturesExtension Methods

using Extensions;

public class ExampleClass{ public void DoSomething() { string s = "Hello Extension Methods"; int i = s.WordCount(); Console.WriteLine(i); }}

Page 27: History of C#

C# 3.0 - Key FeaturesExpression Trees - Parsing

Expression<Func<int, bool>> exprTree = num => num < 5;

ParameterExpression param = (ParameterExpression)exprTree.Parameters[0];BinaryExpression operation = (BinaryExpression)exprTree.Body;ParameterExpression left = (ParameterExpression)operation.Left;ConstantExpression right = (ConstantExpression)operation.Right;

Console.WriteLine("Decomposed expression: {0} => {1} {2} {3}", param.Name, left.Name, operation.NodeType, right.Value);

Page 28: History of C#

C# 3.0 - Key FeaturesExpression Trees - Compiling

Expression<Func<int, bool>> exprTree = num => num < 5;Func<int, bool> result = exprTree.Compile();Console.WriteLine(result(4));

Page 29: History of C#

C# 3.0 - Key FeaturesAnonymous Types

var v = new { Amount = 108, Message = "Hello" };Console.WriteLine(v.Amount + v.Message);

Page 30: History of C#

C# 3.0 - Key FeaturesImplicit Typing (Type Inferencing)

//int i = 5;var i = 5;//string s = "Hello";var s = "Hello";//int[] a = new[] {0, 1, 2};var a = new[] {0, 1, 2};var anon = new { Name = "Terry", Age = 34 };

Page 31: History of C#

C# 3.0 - Key FeaturesLanguage Integrated Query (LINQ)

IEnumerable<Product> products;

var productQuery = products .Where(product => product.Price > 50.0) .Select(product => new { product.Color, product.Price });

Page 32: History of C#

C# 3.0 - Key FeaturesLanguage Integrated Query (LINQ)

var productQuery = from product in products where product.Price > 50.0 select new { product.Color, product.Price };

var expr = from c in customers where c.City = "Vienna" select c;

Page 33: History of C#

C# 3.0 - Demo: Counter3

Page 34: History of C#

C# 3.0 - Demo:ExtensionMethods

Page 35: History of C#

C# 3.0 - Demo: ExpressionTrees

Page 36: History of C#

C# 3.0 - Demo: LinqExample

Page 37: History of C#

April 2010C# 4.0

Page 38: History of C#

C# 4.0 - Key FeaturesLate Binding (dynamic)

object of type dynamic bypasses static type checking.=> if code is not valid, errors are caught at run time!

Page 39: History of C#

C# 4.0 - Key FeaturesLate Binding (dynamic)Dynamic Language Runtime (IronPython)HTML DOMReflection APICOM Interop

Page 40: History of C#

C# 4.0 - Key FeaturesLate Binding (dynamic)

before C# 4.0:

((Excel.Range)excelApp.Cells[1, 1]).Value2 = "Name";Excel.Range range2008 = (Excel.Range)excelApp.Cells[1, 1];

C# 4.0:

// access to the Value property and the conversion to// Excel.Range are handled by the run-time COM binderexcelApp.Cells[1, 1].Value = "Name";Excel.Range range2010 = excelApp.Cells[1, 1];

Page 41: History of C#

C# 4.0 - Demo:DynamicExample

Page 42: History of C#

C# 4.0 - Key FeaturesNamed and optional arguments

Page 43: History of C#

C# 4.0 - Demo:NamedAndOptionalArguments

Page 44: History of C#

August 2012C# 5.0

Page 45: History of C#

C# 5.0 - Key FeaturesAsync

Page 46: History of C#

C# 5.0 - Demo: AsyncConsole

Page 47: History of C#

C# 5.0 - Demo: AsyncExample

Page 48: History of C#

? 2015C# 6

Roslynset of open-source compilers and code analysis APIs for C# and VBApache License 2.0

Language features in C# 6 and VB 14