Presentation is loading. Please wait.

Presentation is loading. Please wait.

卢斌 Software Development Engineer Microsoft Corporation

Similar presentations


Presentation on theme: "卢斌 Software Development Engineer Microsoft Corporation"— Presentation transcript:

1 卢斌 Software Development Engineer Microsoft Corporation
.NET框架2.0新特性综述 卢斌 Software Development Engineer Microsoft Corporation

2 BCL 新功能 Serial port Compression Strongly typed resources
Console support Threading Diagnostics Networking 。。。

3 演 示 Strongly Typed Resources

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

5 Generics “泛型” 为什么要Generics? VB, C#, MC++ 编写和运用 generics Generics国际标准化
编译时类型验证 高性能 (不用装箱box, 不用转换downcasts) 减少代码累赘 (typed collections) VB, C#, MC++ 编写和运用 generics Generics国际标准化

6 Generics in VB VB Dim intList As New List(Of Integer)
Public Class List(Of ItemType)      Private elements() As ItemType      Private elementcount As Integer      Public Sub Add(ByVal element As ItemType)           If elementcount = elements.Length Then Resize(elementcount * 2)           elements(elementcount) = element           count += 1      End Sub      Public Default Property Item(ByVal index As Integer) As ItemType           Get               Return elements(index)           End Get           Set (ByVal Value As ItemType)               elements(index) = Value           End Set      End Property      Public ReadOnly Property Count As Integer               Return elementcount           End Get End Class Dim intList As New List(Of Integer) intList.Add(1)           ‘ No boxing intList.Add(2)           ‘ No boxing intList.Add(“3")     ‘ Compile-time error Dim i As Integer = intList(0)  ’ No cast required

7 Generics in C++ C++ generic<typename T> public ref class List {
   array<T>^ elements;    int count; public:    void Add(T element) {       if (count == elements->Length) Resize(count * 2);       elements[count++] = element;    }    property T default [int index] {       T get() { return elements[index]; }       void set(T value) { elements[index] = value; }    property int Count {       int get() { return count; } }; List<int>^ intList = gcnew List<int>(); intList->Add(1);           // No boxing intList->Add(2);           // No boxing intList->Add(“3");     // Compile-time error int i = intList[0];        // No cast required

8 基础类库泛类 (Generics in BCL)
System.Collections.Generic classes List<T> Dictionary<K, V> Stack<T> Queue<T> System.Collections.Generic interfaces IList<T> IDictionary<K, V> IDictionary<K, V> ICollection<T> IEnumerable<T> IEnumerator<T> IComparable<T> IComparer<T> Nullable(Of T) EventHandler<T> Dim intVal as Nullable(Of Integer) = 5 If intVal.HasValue Then ‘ checks for a value delegate void EventHandler<T>(Object sender, T e) where T : EventArgs;

9 提高 CLR 性能 长远目标: CLR性能指标与非托管本机代码一致 NGEN 减少多个托管进程的marginal cost
减少托管应用程序起动时间和工作集 NGEN 将 IL 编译成本机代码, 然后存盘 好处: 无需反复将 IL 编译成本机代码, 类的布局也已定型, 起动时间更短 CLR 2.0:显著地减少了private, non-shareable工作集 ngen install, ngen update, ngen /queue

10 使.NET框架成为更快的编程平台 提高现有API的性能
降低应用程序域(AppDomain)开销,应用程序域之间的方法调用 (加快 ~1.1倍-50倍) 委托(delegate)创建 (~10倍) 和调用 (~2倍) UTF8Encoding: translation (~2.5倍) 新的高性能 API 更快的资源查找API Lightweight CodeGen: 只生成关键代码 (与 Reflect Emit 对比)

11 演 示 TryParse

12 走向 64 位 64 位 Windows 服务器和工作站 支持 WoW64 VS: 作为32位应用程序运行
支持 IA64 和 X64 (AMD64) Windows Server 2003 SP1和未来的64 位 Windows Client 支持 WoW64 32位应用程序可在 64位机上运行 CLR1.0 和1.1应用程序在 WoW64上运行 VS: 作为32位应用程序运行 可以开发, 调试和部署32位和64位应用程序 新的CLR 64位实时编译, 垃圾回收和程序调试服务

13 C# Compiler /platform:
PE32+ YES NO ILONLY 64bit NO WOW64 YES YES NO 32BITREQUIRED C# Compiler /platform: <AnyCPU>: ILONLY, NOT 32BITREQUIRED <x86>: 32BITREQUIRED <Itanium> or <x64>: PE32+

14 演 示 Space Invaders

15 CLR安全功能 支持新的加密服务(cryptography) DPAPI (Data Protection API) 支持托管ACL
支持 PKI and PKCS7 支持 XML 加密 更好地支持 X509 certificates DPAPI (Data Protection API) 支持托管ACL 提高应用程序安全 Permission 计算器 (PermCalc) Debug-In-Zone

16 演 示 SecureString

17 RAD程序调试 编辑-继续能力 (Edit and Continue) Display Attributes 控制调试器显示
允许的编辑: (例子) 给类加新的private字段 给类加新的private非虚拟方法 改写方法内的代码 不允许的编辑: (例子) 除去字段或方法 编辑泛类 (generics) 序列化(Serialization)不认知新的字段 Display Attributes 控制调试器显示

18 SQL Server 集成 将开发工具 Visual Studio 与数据管理平台 SQL Server 集成在一起
将中间层的.NET框架编程模式和开发技能应用到数据层 用托管代码写 Stored Procedures, Triggers, data types CLR安全系统(类型安全和代码访问安全)

19 定义 Location.Distance()
SQL CLR 功能 VB, C#, … Build 文件集: geo.dll VS .NET 项目 SQL 数据: create assembly … create function … create procedure … create trigger … create type … 定义 Location.Distance() SQL Server SQL Server 承载 CLR SQL Queries: SELECT name FROM Supplier WHERE Location::Distance ) < 3

20 Sql 编程模式 分割字符串 (Splitting a string)
T-SQL 老方法 (T-SQL)…. varchar(200) = 'Microsoft Corporation|SQL Server|2003|SQL-CLR| |11:32:00|Document|3.b.3' SELECT + '|', 0 + 1, + '|', 0 + 1) ), + '|', + '|') + 1, + '|', + '|') + 1) - + '|') - 1 ), + '|', + '|', + '|') + 1) + 1, + '|', + '|', + '|') + 1) + 1) - + '|') + 1) - 1 ), + '|') + 1) + 1) + 1, + '|') + 1) + 1) + 1) - + '|') + 1) + 1) - 1 ), + '|') + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) - 1 ), + '|') + 1) + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) + 1) - 1 ), + '|') + 1) + 1) + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) + 1) + 1) - 1 ), + '|', + '|', + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) + 1) + 1) + 1) - 1 ) varchar(200) = 'Microsoft Corporation|SQL Server|2003|SQL-CLR| |11:32:00|Document|3.b.3' + '|', 0 + 1) ), + '|', 0 + 1, SELECT + '|', + '|') + 1, + '|') + 1) - + '|', + '|') - 1 ), + '|', + '|', + '|') + 1) + 1, + '|', + '|', + '|') + 1) + 1) - + '|') + 1) - 1 ), + '|') + 1) + 1) + 1, + '|') + 1) + 1) + 1) - + '|') + 1) + 1) - 1 ), + '|') + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) - 1 ), + '|') + 1) + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) + 1) - 1 ), + '|') + 1) + 1) + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) + 1) + 1) - 1 ), + '|', + '|', + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1, + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1) - + '|') + 1) + 1) + 1) + 1) + 1) + 1) - 1 )

21 Sql 编程模式 分割字符串 (Splitting a string)
VB 新方法… Public Shared Sub SplitString() Dim s As String s = "Microsoft Corporation|SQL Server|2003|SQL-CLR| |11:32:00|Document|3.b.3" Dim myArray() As String = Split(s, "|") End Sub

22 更多资源 MSDN Dev Center GotDotNet Microsoft Technical Communities
GotDotNet Microsoft Technical Communities CLR Application Compatibility Lab

23 Your Feedback is Important!

24


Download ppt "卢斌 Software Development Engineer Microsoft Corporation"

Similar presentations


Ads by Google