Overview of Visual C# 2005 Henrik Westergaard Hansen

Slides:



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

CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 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.
DEV340 Microsoft Visual C# Under the Covers: An In-Depth Look at C# 2.0 Anders Hejlsberg Distinguished Engineer Microsoft Corporation.
Stuart White 2 Visual Studio 2005 Vision Foster a vibrant partner ecosystem Simplify creation of Connected Systems Improve.
What’s New for Smart Client Developers in Visual Studio 2005? Mike Pelton Systems Engineer Microsoft Ltd
What’s Completely New? Visual Studio Team System! Sean Puffett Developer Evangelist
Team System and Microsoft Solutions Framework Alan Cameron Wills Architect, MSF
C#C# C#C# Kit Colbert Student Consultant representing Microsoft
What’s New in Visual Studio 2005: Security &.NET Framework 2.0 Mike Pelton Developer & Platform Group Microsoft Ltd.
DEV365 Visual Studio Team Edition for Software Architects: Overview Alex Torone Lead Program Manager Enterprise Tools Microsoft Corporation.
Iterator Pattern Dr. Neal CIS 480. Iterator An iterator pattern can be used when one class is a collection of things and would like to provide a standardized.
Visual Studio 2005 Team System: Software Project Management Hans Verbeeck
Professional development with Visual Studio 2005 Team System Aali Alikoski Academic Developer Evangelist Microsoft Oy
Pedro Miguel Rosa Senior Software Engineer Developer Platform Group.
Team System and MSDN Subscriptions Summary Pricing, Licensing & Transition Plan Andreas Nordenadler Product Manager, Developer Tools.
Enabling Better Software through Better Testing Jason Anderson, Microsoft
DEV302 - Visual Studio Team System Building Robust and Reliable Software Eric Lee Program Manager Microsoft Corporation.
Новости в.NET CLR 2.0 Светлин Наков Българска асоциация на разработчиците на софтуер.
ARC312 Tools For Architecture: Designing For Deployment Alex Torone Program Manager Microsoft Corporation Bill.
Visual Studio 2005 Team System: Building Robust & Reliable Software Tejasvi Kumar Technology Specialist - VSTS Microsoft Corporation
Building Robust and Reliable Software Jason Anderson, Microsoft
Visual Studio 2005 Team System: Enterprise Development and Test Sean Puffet Microsoft Ltd
DEV 303 Visual Studio "Whidbey" Enterprise Tools: Source Control and Work Item Tracking Brian Harry Product Unit Manager Microsoft Visual Studio.
Prashant Sridharan Lead Product Manager, Visual Studio Visual Studio 2005.
C#.Net Development Version 1.0. Overview Nullable Datatype Description ? HasValue Lifted Conversions null coalescing operator ?? Partial Classes Copyright.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Visual C# 2005: IDE Enhancements Dan Fernandez C# Product Manager
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
Visual Studio 2005 Team Edition for Software Architects: Developing Service-Oriented Systems Bill Gibson Senior Program Manager Enterprise Tools Microsoft.
DEV 301 Visual Studio Team System Tom Arnold Program Manager Microsoft Corporation “Enabling Better Software through Better Testing”
The Microsoft Application Platform Silvano Coriani Developer Evangelist Microsoft Corporation Gabriele Castellani Developer Evangelist Microsoft Corporation.
C# 2.0 and Future Directions Anders Hejlsberg Technical Fellow Microsoft Corporation.
[ISRAR ALI] Hammad Khan. The namespace keyword is used to declare a scope. Making software components reusable can result in naming collisions (two classes.
Advanced C# Types Tom Roeder CS fa. From last time out parameters difference is that the callee is required to assign it before returning not the.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
Introduction to C# 2.0 An Advanced Look Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Generics Generics vs. heterogeneous collections Doing your own generics FEN 2014UCN Teknologi/act2learn1.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 11 th Lecture Pavel Ježek
ARC310 Microsoft Visual Studio 2005 Team Edition for Software Architects: Developing Logical Datacenters Alex Torone Lead Program Manager Enterprise Tools.
ARC411 Domain Specific Language Tools For Model-Driven Development In Microsoft Visual Studio 2005 Jochen Seemann Program Manager Enterprise Tools Microsoft.
Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation
Visual Studio 2005 Team System: Enabling Better Software Through Testing Tejasvi Kumar Technology Specialist - VSTS Microsoft Corporation
Visual Studio 2005 Team System: Software Project Management Brian A White Microsoft
Visual Studio 2005 C#VBC++J#WebExpress Visual Studio Standard Edition Visual Studio Professional Edition Novices Enthusiasts Students Hobbyists Part-Timers.
Visual Basic 2005: Advanced Language and IDE Features Amanda Silver Program Manager Visual Basic Session Code: DEV343.
1 Introduction Bindia Hallauer & Ajay Sudan Product Management, Visual Studio Team System Microsoft Corporation.
DEV466 Microsoft Visual Studio 2005 Team System: Enterprise-Class Source Control Doug Neumann Program Manager Visual Studio Microsoft Corporation.
Chapter  Array-like data structures  ArrayList  Queue  Stack  Hashtable  SortedList  Offer programming convenience for specific access.
CSharp Overview Joe Healy Why C# ? First component-oriented language –Builds on COM+ experience –Native support for Namespaces; Versioning.
WEB330 ASP.NET: Using Microsoft Visual 2005 Studio Team System to Build Enterprise Web Applications Brian Goldfarb Product Manager Web Platform and Tools.
1 New Features in C# 2.0 Generic Types Iterators Simplified Delegates Anonymous Methods Partial Types Various © University of Linz, Institute for System.
Visual Studio 2005, and.NET 2.0 Michael Juřek Microsoft Czech Republic Software Architect
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
Advance your career with a new generation of Microsoft certifications TargetedCurrent Cost-effective Easier to Distinguish Learn more, learn better Put.
DEV260 Microsoft Visual Studio 2005 Team System: Managing the Software Lifecycle with Visual Studio 2005 Team System Bindia Hallauer Senior Product Manager.
Introduction to .NET Generics
Visual Studio Tools for Office 2005
Chapter 5: Programming with C#
.NET and .NET Core 9. Towards Higher Order Pan Wuming 2017.
Visual C# "Whidbey": Language Enhancements
Visual C# 2005: Language Enhancements
Tech Ed 2004 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express.
DEV321 Visual C# 2005: Language Enhancements
DAT381 Team Development with SQL Server 2005
Getting Ready for Visual Studio 2005
How to organize and document your classes
Mark Quirk Head of Technology Developer & Platform Group
Visual C# 2005: Language Enhancements
Presentation transcript:

Overview of Visual C# 2005 Henrik Westergaard Hansen

Agenda Generics Nullable Types Anonymous methods Iterators Partial types Other enhancements IDE Enhancements

public class List { private object[] elements; private object[] elements; private int count; private int count; public void Add(object element) { public void Add(object element) { if (count == elements.Length) Resize(count * 2); if (count == elements.Length) Resize(count * 2); elements[count++] = element; elements[count++] = element; } public object this[int index] { public object this[int index] { get { return elements[index]; } get { return elements[index]; } set { elements[index] = value; } set { elements[index] = value; } } public int Count { public int Count { get { return count; } get { return count; } }} Generics public class List public class List { private T[] elements; private T[] elements; private int count; private int count; public void Add(T element) { public void Add(T element) { if (count == elements.Length) Resize(count * 2); if (count == elements.Length) Resize(count * 2); elements[count++] = element; elements[count++] = element; } public T this[int index] { public T this[int index] { get { return elements[index]; } get { return elements[index]; } set { elements[index] = value; } set { elements[index] = value; } } public int Count { public int Count { get { return count; } get { return count; } }} List intList = new List(); intList.Add(1);intList.Add(2);intList.Add("Three"); int i = (int)intList[0]; List intList = new List(); intList.Add(1);// Argument is boxed intList.Add(2);// Argument is boxed intList.Add("Three");// Should be an error int i = (int)intList[0];// Cast required List intList = new List (); intList.Add(1);// No boxing intList.Add(2);// No boxing intList.Add("Three");// Compile-time error int i = intList[0];// No cast required

Generics Why generics? Type checking, no boxing, no downcasts Reduced code bloat (typed collections) How are C# generics implemented? Instantiated at run-time, not compile-time Checked at declaration, not instantiation Work for both reference and value types Complete run-time type information

Generics Type parameters can be applied to Class, struct, interface, and delegate types class Dictionary {…} struct HashBucket {…} interface IComparer {…} delegate R Function (A arg); Dictionary customerLookupTable; Dictionary > orderLookupTable; Dictionary numberSpellings;

Generics Type parameters can be applied to Class, struct, interface, and delegate types Methods class Utils { public static T[] CreateArray (int size) { public static T[] CreateArray (int size) { return new T[size]; return new T[size]; } public static void SortArray (T[] array) { public static void SortArray (T[] array) { … }} string[] names = Utils.CreateArray (3); names[0] = "Jones"; names[1] = "Anderson"; names[2] = "Williams"; Utils.SortArray(names);

Generics Type parameters can be applied to Class, struct, interface, and delegate types Methods Type parameters can have constraints One base class, multiple interfaces, new()

Generics class Dictionary class Dictionary { public void Add(K key, V value) { public void Add(K key, V value) { … if (((IComparable)key).CompareTo(x) == 0) {…} if (((IComparable)key).CompareTo(x) == 0) {…} … }} class Dictionary where K: IComparable { public void Add(K key, V value) { public void Add(K key, V value) { … if (key.CompareTo(x) == 0) {…} if (key.CompareTo(x) == 0) {…} … }} class Dictionary : IDictionary class Dictionary : IDictionary where K: IComparable where K: IComparable where V: IKeyProvider, IPersistable, new() where V: IKeyProvider, IPersistable, new() { public void Add(K key, V value) { … }}

public class List public class List { public void Add(T item) {…} public void Add(T item) {…} public T this[int index] {…} public T this[int index] {…} …} public class List : IList { public void Add(T item) {…} public void Add(T item) {…} public T this[int index] {…} public T this[int index] {…} …} public interface IList { public void Add(object item); public void Add(object item); public object this[int index] {…} public object this[int index] {…} …} Generics Generics are “invariant” Interfaces can be used for type neutrality List<object>List<int>List<string> object

Generics T.default Null checks Type casts void Foo () { T x = null;// Error (if T.valuetype) T x = null;// Error (if T.valuetype) T y = T.default;// Ok T y = T.default;// Ok} void Foo (T x) { if (x == null) { if (x == null) { throw new FooException(); throw new FooException(); } …} void Foo (T x) { int i = (int)x;// Error int i = (int)x;// Error int j = (int)(object)x;// Ok int j = (int)(object)x;// Ok}

Generics Collection classes Collection interfaces Collection base classes Utility classes Reflection Native support in IL and CLR LinkedList List LinkedList List Dictionary<K,V>SortedDictionary<K,V>Stack<T>Queue<T> IList<T>IDictionary<K,V>ICollection<T>IEnumerable<T>IEnumerator<T>IComparable<T>IComparer<T> Collection<T>KeyedCollection<T>ReadOnlyCollection<T> Nullable<T>EventHandler<T>Comparer<T>

Generics System.Nullable<T> Provides nullability for any type Struct that combines a T and a bool Conversions between T and Nullable Conversions between T and Nullable Conversion from null literal to Nullable Conversion from null literal to Nullable Nullable x = 123; Nullable y = null; int i = (int)x; int j = x.Value; if (x.HasValue) Console.WriteLine(x.Value); Console.WriteLine(x.Value);

Nullable Types T? same as System.Nullable T? same as System.Nullable null literal conversions Nullable conversions int? x = 123; double? y = 1.25; int? x = null; double? y = null; int i = 123; int? x = i;// int --> int? double? y = x;// int? --> double? int? z = (int?)y;// double? --> int? int j = (int)z;// int? --> int

Anonymous Methods class MyForm : Form { ListBox listBox; ListBox listBox; TextBox textBox; TextBox textBox; Button addButton; Button addButton; public MyForm() { public MyForm() { listBox = new ListBox(...); listBox = new ListBox(...); textBox = new TextBox(...); textBox = new TextBox(...); addButton = new Button(...); addButton = new Button(...); addButton.Click += new EventHandler(AddClick); addButton.Click += new EventHandler(AddClick); } void AddClick(object sender, EventArgs e) { void AddClick(object sender, EventArgs e) { listBox.Items.Add(textBox.Text); listBox.Items.Add(textBox.Text); }} class MyForm : Form { ListBox listBox; ListBox listBox; TextBox textBox; TextBox textBox; Button addButton; Button addButton; public MyForm() { public MyForm() { listBox = new ListBox(...); listBox = new ListBox(...); textBox = new TextBox(...); textBox = new TextBox(...); addButton = new Button(...); addButton = new Button(...); addButton.Click += delegate { addButton.Click += delegate { listBox.Items.Add(textBox.Text); listBox.Items.Add(textBox.Text); }; }; }}

Anonymous Methods Allows code block in place of delegate Delegate type automatically inferred Code block can be parameterless Or code block can have parameters In either case, return types must match button.Click += delegate { MessageBox.Show("Hello"); }; button.Click += delegate(object sender, EventArgs e) { MessageBox.Show(((Button)sender).Text); };

Generic Delegates and List Methods System.Action - Performs an action on the specified object List.ForEach - Performs specified action on each element System.Predicate - Defines a set of criteria data must meet List.Find/FindIndex/FindAll/FindLast – Filters data based on predicate List.TrueForAll - Determines whether every element meets criteria in predicate public sealed delegate void Action ( T obj ); public sealed delegate bool Predicate ( T obj ); public T Find( Predicate match ); public void ForEach( Action action ); public bool TrueForAll( Predicate match );

Using Anonymous Methods List numbers = new List (); numbers.Add(1);numbers.Add(1); numbers.Add(6); numbers.Add(2); int sum = 0; numbers.ForEach(delegate(int i) { sum += i; }); { sum += i; }); Console.WriteLine(sum); //Print 10 int match = numbers.FindIndex(delegate(int i) { return i == 6; }); { return i == 6; }); Console.WriteLine(match); //Print 2 bool check = numbers.TrueForAll(delegate(int i) { return i > 0; }); { return i > 0; }); Console.WriteLine(check); //Print True ForEach FindIndex TrueForAll Generic List

Demo #1 Generics Performance

Iterators foreach relies on “enumerator pattern” GetEnumerator() method foreach makes enumerating easy foreach (object obj in list) { DoSomething(obj); DoSomething(obj);} Enumerator e = list.GetEnumerator(); while (e.MoveNext()) { object obj = e.Current; object obj = e.Current; DoSomething(obj); DoSomething(obj);}

Iterators public class List { internal object[] elements; internal object[] elements; internal int count; internal int count; public ListEnumerator GetEnumerator() { return new ListEnumerator(this); public ListEnumerator GetEnumerator() { return new ListEnumerator(this); }} public class ListEnumerator : IEnumerator { List list; List list; int index; int index; internal ListEnumerator(List list) { internal ListEnumerator(List list) { this.list = list; this.list = list; index = -1; index = -1; } public bool MoveNext() { public bool MoveNext() { int i = index + 1; int i = index + 1; if (i >= list.count) return false; if (i >= list.count) return false; index = i; index = i; return true; return true; } public object Current { public object Current { get { return list.elements[index]; } get { return list.elements[index]; } }}

public class List { public IEnumerator GetEnumerator() { public IEnumerator GetEnumerator() { for (int i = 0; i < count; i++) { yield return elements[i]; for (int i = 0; i < count; i++) { yield return elements[i]; } }} Iterators Method that incrementally computes and returns a sequence of values yield return and yield break Must return IEnumerator or IEnumerable public IEnumerator GetEnumerator() { return new __Enumerator(this); return new __Enumerator(this);} private class __Enumerator: IEnumerator { object current; object current; int state; int state; public bool MoveNext() { public bool MoveNext() { switch (state) { switch (state) { case 0: … case 0: … case 1: … case 1: … case 2: … case 2: … … } } public object Current { public object Current { get { return current; } get { return current; } }}

public class List public class List { public IEnumerator GetEnumerator() { public IEnumerator GetEnumerator() { for (int i = 0; i < count; i++) yield return elements[i]; for (int i = 0; i < count; i++) yield return elements[i]; } public IEnumerable Descending() { public IEnumerable Descending() { for (int i = count - 1; i >= 0; i--) yield return elements[i]; for (int i = count - 1; i >= 0; i--) yield return elements[i]; } public IEnumerable Subrange(int index, int n) { public IEnumerable Subrange(int index, int n) { for (int i = 0; i < n; i++) yield return elements[index + i]; for (int i = 0; i < n; i++) yield return elements[index + i]; }} Iterators List items = GetItemList(); foreach (Item x in items) {…} foreach (Item x in items.Descending()) {…} foreach (Item x in Items.Subrange(10, 20)) {…}

Partial Types public partial class Customer { private int id; private int id; private string name; private string name; private string address; private string address; private List orders; private List orders;} public partial class Customer { public void SubmitOrder(Order order) { public void SubmitOrder(Order order) { orders.Add(order); orders.Add(order); } public bool HasOutstandingOrders() { public bool HasOutstandingOrders() { return orders.Count > 0; return orders.Count > 0; }} public class Customer { private int id; private int id; private string name; private string name; private string address; private string address; private List orders; private List orders; public void SubmitOrder(Order order) { public void SubmitOrder(Order order) { orders.Add(order); orders.Add(order); } public bool HasOutstandingOrders() { public bool HasOutstandingOrders() { return orders.Count > 0; return orders.Count > 0; }}

Other Enhancements Static classes Can contain only static members Cannot be type of variable, parameter, etc. System.Console, System.Environment, etc. public static class Math { public static double Sin(double x) {…} public static double Sin(double x) {…} public static double Cos(double x) {…} public static double Cos(double x) {…} …}

Other Enhancements Property accessor accessibility Allows one accessor to be restricted further Typically set {…} more restricted than get {…} public class Customer { private string id; private string id; public string CustomerId { public string CustomerId { get { return id; } get { return id; } internal set { id = value; } internal set { id = value; } }}

Other Enhancements Namespace alias qualifier A::B looks up A only as namespace alias global::X starts lookup in global namespace using IO System.IO; using IO = System.IO; class Program { static void Main() { static void Main() { IO::Stream s = new IO::File.OpenRead("foo.txt"); IO::Stream s = new IO::File.OpenRead("foo.txt"); global::System.Console.WriteLine("Hello"); global::System.Console.WriteLine("Hello"); }}

Other Enhancements Fixed size buffers C style embedded arrays in unsafe code public struct OFSTRUCT { public byte cBytes; public byte cBytes; public byte fFixedDisk; public byte fFixedDisk; public short nErrCode; public short nErrCode; private int Reserved; private int Reserved; public fixed char szPathName[128]; public fixed char szPathName[128];}

Other Enhancements #pragma warning Control individual warnings in blocks of code using System; class Program { [Obsolete] [Obsolete] static void Foo() {} static void Foo() {} static void Main() { static void Main() { #pragma warning disable 612 Foo(); Foo(); #pragma warning restore 612 }}

Visual Studio Team System Change ManagementWork Item TrackingReportingProject Portal Visual Studio Team Foundation Server Integration ServicesProject Management Process and Architecture Guidance Dynamic Code Analyzer Visual Studio Team Edition Software Architects Static Code AnalyzerCode ProfilerUnit TestingCode CoverageTeam Explorer (includes Team Foundation Server CAL)Visual Studio Professional EditionLoad TestingManual TestingTest Case ManagementApplication DesignerSystem DesignerLogical Datacenter Designer Visual Studio Team Edition Software Developers Visual Studio Team Edition Software Testers Visual Studio Industry Partners Team BuildClass Designer (in Visual Studio Standard Edition and higher) Deployment DesignerVisio for Enterprise Architects (in MSDN Premium Subscription)

Smart Clients Web Services & Offline/Online support Device Adaptability Tough to Deploy Heavy Footprint DLL Hell Network Dependency Poor User Experience Rich UI Complex To Develop Rich User Experience Developer Productivity Responsive Broad Reach Easy Change Management Ease of Deployment

Resources MSDN asp?url=/library/en- us/dnvs05/html/csharp_generics.asp asp?url=/library/en- us/dnvs05/html/csharp_generics.asp es/04/05/C20/default.aspx es/04/05/C20/default.aspx

© Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.