Ken Casada Developer Evangelist Microsoft Switzerland

Slides:



Advertisements
Similar presentations
1 Visual C# "Whidbey": Language Enhancements Anders Hejlsberg Distinguished Engineer Microsoft Corporation Anders Hejlsberg Distinguished.
Advertisements

Dynamic internals. Introductions  Alexandru Ghiondea  C# Compiler QA  
Generics, Lists, Interfaces
Deep Dive into LINQ Eran Sharabi.NET Development Team Leader JohnBryce Training
 Anders Hejlsberg Technical Fellow Microsoft Corporation TL16.
What's new in Microsoft Visual C Preview
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 6 th Lecture Pavel Ježek
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Bart J.F. De Smet Software Development Engineer Microsoft Corporation Session Code: DTL304.
C# Types Tom Roeder CS fa. Administration CMS is up let me know if you can’t see the course Assignments are posted may not be able to do some.
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
Visual Studio 2010 and.NET Framework 4 Training Workshop.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
What’s New in C# 4.0? Pavel Yosifovich SELA Group
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Basic Elements of C++ Chapter 2.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Gurinder CTO. Lisa Feigenbaum Microsoft Program Manager Visual Studio Languages
demo video demo Dynamic Languages Simple and succinctImplicitly typedMeta-programmingNo compilation Static Languages RobustPerformantIntelligent.
Louis de Klerk Consultant Inobits Consulting DTL308.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
Laboratory Study October, The very first example, traditional "Hello World!" program: public class first { public static void main (String[ ]
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 7 th & 8 th Lecture Pavel Ježek.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Eric Vogel Software Developer A.J. Boggs & Company.
Dynamic Languages & The.Net Framework Shay Friedman ActionBase
Alex Turner C# Compiler PM Session Code: DEV402 On the Dynamic menu today… The Dynamic Language Runtime How does it relate to the CLR? Dynamic in C#
 Jim Hugunin Partner Architect Microsoft Corporation TL10.
Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); object calc.
© FPT Software Advanced features in C# 1. © FPT Software Agenda Attributes Delegates & Events Anonymous Types & Dynamic Type Extension Methods Lambda.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
Lisa Feigenbaum Microsoft Program Manager Session Code: DEV314.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
C Sharp Web & Internet Programming Group Diana, Aren, Jeff, & Adam, Farrin 5/5/20081CS 311.
Ahmed Salijee Developer Advisor
Chapters 2 & 3. .NET Software development model that allows applications created in disparate programming languages to communicate Universal data access.
Inside LINQ to Objects How LINQ to Objects work Inside LINQ1.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Scott Hanselman Principal Program Manager Microsoft DTL303.
A comparison of C-Sharp and Java Zunaid Jogee Supervisor: T. Stakemire.
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
Jonathan Aneja Program Manager Microsoft Corporation Session Code: DTL336 Anders Hejlsberg Technical Fellow Microsoft Corporation.
LINQ Language Integrated Query LINQ1. LINQ: Why and what? Problem Many data sources: Relational databases, XML, in-memory data structures, objects, etc.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Luke Hoban Senior Program Manager Microsoft Session Code: DTL310.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel 1 בס " ד.
Введение в DLR UNETA 16 апреля, 2010 Иван Колодяжный, Software Developer Teamdev Ltd.
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 7 th Lecture Pavel Ježek
Visual Studio 2010 and.NET Framework 4 Training Workshop.
Methods Attributes Method Modifiers ‘static’
Advanced .NET Programming I 7th Lecture
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Computing with C# and the .NET Framework
C# in the Big World Mads Torgersen Program Manager
Visual Studio 2010 and .NET Framework 4 Training Workshop
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Tech·Ed North America /18/2018 5:14 PM
Advanced .NET Programming I 8th Lecture
Presentation transcript:

Ken Casada Developer Evangelist Microsoft Switzerland

C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query

Declarative ConcurrentDynamic

What How ImperativeDeclarative

Dynamic Languages Simple and succinct Implicitly typed Meta- programming No compilation Static Languages RobustPerformantIntelligent toolsBetter scaling

C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming

Dynamically Typed Objects Optional and Named Parameters Improved COM Interoperability Co- and Contra-variance

Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPythonIronPythonIronRubyIronRubyC#C#VB.NETVB.NETOthers…Others…

Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); ScriptObject calc = GetCalculator(); object res = calc.Invoke("Add", 10, 20); int sum = Convert.ToInt32(res); ScriptObject calc = GetCalculator(); object res = calc.Invoke("Add", 10, 20); int sum = Convert.ToInt32(res); dynamic calc = GetCalculator(); int sum = calc.Add(10, 20); dynamic calc = GetCalculator(); int sum = calc.Add(10, 20); Statically typed to be dynamic Dynamic method invocation Dynamic conversion

dynamic x = 1; dynamic y = "Hello"; dynamic z = new List { 1, 2, 3 }; dynamic x = 1; dynamic y = "Hello"; dynamic z = new List { 1, 2, 3 }; Compile-time type dynamic Run-time type System.Int32 When operand(s) are dynamic… Member selection deferred to run-time At run-time, actual type(s) substituted for dynamic Static result type of operation is dynamic

public static class Math { public static decimal Abs(decimal value); public static double Abs(double value); public static float Abs(float value); public static int Abs(int value); public static long Abs(long value); public static sbyte Abs(sbyte value); public static short Abs(short value);... } public static class Math { public static decimal Abs(decimal value); public static double Abs(double value); public static float Abs(float value); public static int Abs(int value); public static long Abs(long value); public static sbyte Abs(sbyte value); public static short Abs(short value);... } double x = 1.75; double y = Math.Abs(x); double x = 1.75; double y = Math.Abs(x); dynamic x = 1.75; dynamic y = Math.Abs(x); dynamic x = 1.75; dynamic y = Math.Abs(x); Method chosen at compile-time: double Abs(double x) Method chosen at run-time: double Abs(double x) dynamic x = 2; dynamic y = Math.Abs(x); dynamic x = 2; dynamic y = Math.Abs(x); Method chosen at run-time: int Abs(int x)

public abstract class DynamicObject : IDynamicObject { public virtual object GetMember(GetMemberBinder info); public virtual object SetMember(SetMemberBinder info, object value); public virtual object DeleteMember(DeleteMemberBinder info); public virtual object UnaryOperation(UnaryOperationBinder info); public virtual object BinaryOperation(BinaryOperationBinder info, object arg); public virtual object Convert(ConvertBinder info); public virtual object Invoke(InvokeBinder info, object[] args); public virtual object InvokeMember(InvokeMemberBinder info, object[] args); public virtual object CreateInstance(CreateInstanceBinder info, object[] args); public virtual object GetIndex(GetIndexBinder info, object[] indices); public virtual object SetIndex(SetIndexBinder info, object[] indices, object value); public virtual object DeleteIndex(DeleteIndexBinder info, object[] indices); public MetaObject IDynamicObject.GetMetaObject(); } public abstract class DynamicObject : IDynamicObject { public virtual object GetMember(GetMemberBinder info); public virtual object SetMember(SetMemberBinder info, object value); public virtual object DeleteMember(DeleteMemberBinder info); public virtual object UnaryOperation(UnaryOperationBinder info); public virtual object BinaryOperation(BinaryOperationBinder info, object arg); public virtual object Convert(ConvertBinder info); public virtual object Invoke(InvokeBinder info, object[] args); public virtual object InvokeMember(InvokeMemberBinder info, object[] args); public virtual object CreateInstance(CreateInstanceBinder info, object[] args); public virtual object GetIndex(GetIndexBinder info, object[] indices); public virtual object SetIndex(SetIndexBinder info, object[] indices, object value); public virtual object DeleteIndex(DeleteIndexBinder info, object[] indices); public MetaObject IDynamicObject.GetMetaObject(); }

public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding); public StreamReader OpenTextFile( string path, Encoding encoding); public StreamReader OpenTextFile( string path); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding); public StreamReader OpenTextFile( string path, Encoding encoding); public StreamReader OpenTextFile( string path); Primary method Secondary overloads Call primary with default values

public StreamReader OpenTextFile( string path, Encoding encoding = null, bool detectEncoding = true, int bufferSize = 1024); public StreamReader OpenTextFile( string path, Encoding encoding = null, bool detectEncoding = true, int bufferSize = 1024); Optional parameters OpenTextFile("foo.txt", Encoding.UTF8); OpenTextFile("foo.txt", Encoding.UTF8, bufferSize: 4096); Named argument OpenTextFile( bufferSize: 4096, path: "foo.txt", detectEncoding: false); OpenTextFile( bufferSize: 4096, path: "foo.txt", detectEncoding: false); Named arguments must be last Non-optional must be specified Arguments evaluated in order written Named arguments can appear in any order

object fileName = "Test.docx"; object missing = System.Reflection.Missing.Value; doc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); object fileName = "Test.docx"; object missing = System.Reflection.Missing.Value; doc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); doc.SaveAs("Test.docx"); doc.SaveAs("Test.docx");

Optional and named parameters Optional “ref” modifier Interop type embedding (“No PIA”)

object  dynamic mapping … you can now say excel.Cells[1, 1].Value = "Hello"; instead of ((Excel.Range)excel.Cells[1, 1]).Value2 = "Hello"; … and Excel.Range range = excel.Cells[1, 1]; instead of Excel.Range range = (Excel.Range)excel.Cells[1, 1]; … you can now say excel.Cells[1, 1].Value = "Hello"; instead of ((Excel.Range)excel.Cells[1, 1]).Value2 = "Hello"; … and Excel.Range range = excel.Cells[1, 1]; instead of Excel.Range range = (Excel.Range)excel.Cells[1, 1];

void Process(object[] objects) { … } string[] strings = GetStringArray(); Process(strings); string[] strings = GetStringArray(); Process(strings); void Process(object[] objects) { objects[0] = "Hello"; // Ok objects[1] = new Button(); // Exception! } void Process(object[] objects) { objects[0] = "Hello"; // Ok objects[1] = new Button(); // Exception! } List strings = GetStringList(); Process(strings); List strings = GetStringList(); Process(strings); void Process(IEnumerable objects) { … }.NET arrays are co-variant …but not safely co-variant Until now, C# generics have been invariant void Process(IEnumerable objects) { // IEnumerable is read-only and // therefore safely co-variant } void Process(IEnumerable objects) { // IEnumerable is read-only and // therefore safely co-variant } C# 4.0 supports safe co- and contra-variance

public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } public interface IEnumerator { T Current { get; } bool MoveNext(); } out = Co-variant Output positions only IEnumerable strings = GetStrings(); IEnumerable objects = strings; IEnumerable strings = GetStrings(); IEnumerable objects = strings; Can be treated as less derived public interface IComparer { int Compare(T x, T y); } public interface IComparer { int Compare(T x, T y); } public interface IComparer { int Compare(T x, T y); } public interface IComparer { int Compare(T x, T y); } IComparer objComp = GetComparer(); IComparer strComp = objComp; IComparer objComp = GetComparer(); IComparer strComp = objComp; in = Contra-variant Input positions only Can be treated as more derived

Supported for interface and delegate types Value types are always invariant IEnumerable is not IEnumerable

System.Collections.Generic.IEnumerable System.Collections.Generic.IEnumerator System.Linq.IQueryable System.Collections.Generic.IComparer System.Collections.Generic.IEqualityComparer System.IComparable System.Collections.Generic.IEnumerable System.Collections.Generic.IEnumerator System.Linq.IQueryable System.Collections.Generic.IComparer System.Collections.Generic.IEqualityComparer System.IComparable Interfaces System.Func System.Action System.Predicate System.Comparison System.EventHandler System.Func System.Action System.Predicate System.Comparison System.EventHandler Delegates

C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming

C# 4.0 Samples and Whitepaper Visual C# Developer Center C# team member’s blogs

14 – 15 avril 2010, CICG

Classic Sponsoring Partners Premium Sponsoring Partners