Download presentation
Presentation is loading. Please wait.
Published byMerilyn Bridges Modified over 6 years ago
1
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2005
Visual Studio 2005 Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2005
2
References C# Programming Language, Anders Hejlsberg, et. al., Addison-Wesley, 2004 Pro C# 2005, and the .Net 2.0 Platform, Andrew Troelsen, Apress 2005 Visual C#, A Developer’s Notebook, Jesse Liberty, OReilly, 2005 ASP.NET 2.0, Core Reference, Dino Exposito, Microsoft Press, 2005
3
Additions to C# Generics Iterators Anonymous Methods Partial Types
Static Classes Nullable Type Delegate Covariance and Contravariance
4
C# Generics C++ Class Template Syntax: template <class T> class stack { … }; stack<widget> wStack; C# Generics Syntax public class stack<T> { … } stack<widget> wStack = new stack<widget>();
5
Comparison C++ Templates CLR Generics Type safe Bind at compile time
Has specializations Supports template methods Supports partial template specialization Does not need constraints Calls on methods of a parameter type can be checked because the parameter type is known then. Does not share implementations for any type CLR Generics Type safe Bind at run-time No specializations Supports Generic methods Uses constraints Supports compile-time verification that methods called on a parameter type are correct Shares implementation among all instances for reference types Does not share implementations for value types
6
Second Look at Generics
The “shares implementation for reference types” is important. It says that generics are essentially cosmetic. We don’t have to explicitly cast items extracted from a generic container, but the underlying representation is still object. The explicit cast we had to do is now done by the generic machinery, but we still pay the performance hit for the cast.
7
Constraints on Generics
Constraints are an optional list of type requirements declared with the where keyword: Public class Dictionary<k,v> where k : IComparable { public void Add( k key, v value ) { … // constraint tells compiler that object key has // CompareTo() method if ( key.CompareTo(x) < 0 ) { … } … } }
8
Iterators An iterator block is a block that yields an ordered sequence of values. An iterator block is distinguished by the presence of one or more yield statements. A function that contains this block may not have out or ref parameters or a return statement. See example on next slide.
9
Iterator Example Class stack<T> : IEnumerable<T> { T[ ] items; int count; : public IEnumerator<T> GetEnumerator() { for(int i = count-1; i>=0; --i) yield return items[i]; } } Note that the operation of this function is NOT what its code advertises.
10
Anonymous Methods Anonymous methods support creation of an inline delegate: public delegate void aDelType(string); public event aDelType aDel; : aDel += delegate(string str) { // code }; The delegate arguments may be omitted if the code does not use them.
11
Method Group Conversions
An implicit conversion exists from a method group to a compatible delegate: public delegate void aDelType(string); public event aDelType aDel; : void myHandler(string str) { … } : aDel += myHandler; Here, aDelType(string) is a method group.
12
Partial Types A C# class can now be split across two or more files.
The visual studio wizards now place designer code in a separate file, so you don’t have to print that when you want a hard copy of the class. Syntax: public partial class my class { // code } public partial class my class { // more code } Now we can print out all the developer’s code without having to display the designer code.
13
Static Classes A class can be declared as static:
All class members are static. You can not use new to instantiate an instance. They may not define instance constructors. They are sealed.
14
Nullable Type Represents a value of type T that may be null:
Nullable<int> x = null; Nullable<string> y = null; Can be used to represent: nullable columns in a database optional attributes in an XML element
15
Delegate Covariance and Contravariance
Covariance permits a delegate typed to invoke a method with base return type to bind to a function returning a class derived from base. Contravariance permits a delegate typed to invoke a method with base parameters to bind to a function passing derived parameters, supporting polymorphism.
16
Visual Studio IDE Changes to the IDE
Can save several IDE configuration settings to suit specific tasks UML diagrammer / code generator Code Refactoring Tool Code Snippets Improved Object Viewer in Debugger Debugging Visualizers
17
Support for Cleaning up and Documenting Code
Create UML diagrams from classes and classes from UML diagrams. Refactor Code Change method or parameter name everywhere Factor out method by selecting lines
18
Create UML Class Diagrams with Code and Vice Versa
19
Refactor Code
20
Code Snippets Select code, right-click, and select code snippet:
Get context menu with choices like if, for, while, … Wraps code with the selected construct in an intelligent, easy-to-use way.
22
Debugging Visualizers
23
WinForms Many New Controls: Asynchronous Tasks One-click Deployment
Tools strips Validation Window splitter Asynchronous Tasks One-click Deployment
24
New Controls, Better Object View
25
Asynchronous Tasks Uses BackgroundWorker class
RunWorkerAsync raises a DoWork event That causes a Designer wired delegate to call backgroundWorker1_DoWork(sender,args);
26
Asynchronous Tasks
27
WebForms No longer need IIS for development
Built-in Forms-based security Roles Master pages Themes Personalization support Easier data access
28
Samples and Help, C#
29
Samples and Help, C++
30
Samples and Help, ASP.Net
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.