NETFramework基本类库深入探讨课件.ppt

上传人:牧羊曲112 文档编号:1286664 上传时间:2022-11-04 格式:PPT 页数:37 大小:337.64KB
返回 下载 相关 举报
NETFramework基本类库深入探讨课件.ppt_第1页
第1页 / 共37页
NETFramework基本类库深入探讨课件.ppt_第2页
第2页 / 共37页
NETFramework基本类库深入探讨课件.ppt_第3页
第3页 / 共37页
NETFramework基本类库深入探讨课件.ppt_第4页
第4页 / 共37页
NETFramework基本类库深入探讨课件.ppt_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《NETFramework基本类库深入探讨课件.ppt》由会员分享,可在线阅读,更多相关《NETFramework基本类库深入探讨课件.ppt(37页珍藏版)》请在三一办公上搜索。

1、DEV407: .NET Framework: 基本类库深入探讨 张谦Technical SpecialistMicrosoft (China),DEV407: .NET Framework: 基本类库深,议题,介绍基本数据类型字符串规则表达式CollectionsIO序列化,议题介绍,介绍,Visual Studio.NET,介绍WindowsCOM+ ServicesCommon L,介绍,Globalization,Diagnostics,Configuration,Collections,Resources,Reflection,Net,IO,Threading,Text,Servic

2、eProcess,Security,Runtime,InteropServices,Remoting,Serialization,Base Class Libraries,System,System,Text,Globalization,IO,Collections,Serialization,Text.RegularExpressions,介绍GlobalizationDiagnosticsConf,.NET 统一的编程模型,Windows API,.NET 统一的编程模型Windows API.NET Fr,介绍,基本类库的目的:支持Framework提供通用,众所周知的功能使用简单强大的

3、并且灵活,介绍基本类库的目的:,议题,介绍字符串规则表达式CollectionsIO序列化,基本数据类型System,议题介绍,基本数据类型,原始的和通用的类型Byte, Int16, Decimal, DateTime, 等等.格式化和解析功能ToString 和 Parse 转换成其他类型使用Convert类对象原始的形态,基本数据类型原始的和通用的类型,基本数据类型格式化和解析,影响所有基本数据类型通过 ToString 和 Parse支持格式化是自动认知场景(locale-aware)Thread.CurrentThread.CurrentCulture通过IFormatProvide

4、rs支持控制格式化通用格式化提供者包括CultureInfo, DateTimeFormatInfo,和 NumberFormatInfo,基本数据类型格式化和解析影响所有基本数据类型,基本数据类型格式化:实例 (片断),Double d = 123.4;/ 流通符号, “$123.40” (in en-US)label2.Text = d.ToString(c);/工程符号,“1.234000e+002”label3.Text = d.ToString(“e);DateTime dt = DateTime.Now;/Picture formatting, “19 Jun 2001” (in

5、en-US)label6.Text = dt.ToString(“dd MMM yyyy);/ 日期格式, “6/19/2001 6:35:09 PM”label4.Text = dt.ToString();,基本数据类型格式化:实例 (片断)Double d = 1,格式化,这个例子着重强调了在Framework中格式化是多么的强大和简单,格式化这个例子着重强调了在Framework中格式化是多么的,议题,介绍基本数据类型规则表达式CollectionsIO序列化,字符串System,123.45,议题介绍123.45,生成字符串,串联是非常普遍的String.Concat(strA, st

6、rB, strC) strA & strB & strCStrings 是不可改变的使用 StringBuilder 增加字符串转换函数返回一个新的字符串 (e.g., ToUpper, ToLower, Trim)s.Trim().ToUpper().Equals(k.Trim().ToUpper(),生成字符串串联是非常普遍的,字符串比较,顺序的 (culturally-ignorant) 和感知当地文化的(culturally-aware)比较CompareOrdinal 和 Equals 是顺序的Compare 是 culturally-aware对于包装全球化的功能非常有益在Win9

7、x, Windows 2000 and NT4平台上通用的比较数据的方法,字符串比较顺序的 (culturally-ignorant),字符串格式化,为输出和显示给用户的目的需要格式化字符串控制格式,宽度,填充,对齐方式用picture string或者代码来确定格式String.Format(“Please order 0 widgets at 1 each.”, numWidgets, price)String.Format(“0,10:#00.00”, f)Console.WriteLine(“0:U”, DateTime.Now),字符串格式化为输出和显示给用户的目的需要格式化字符串,

8、议题,介绍基本数据类型字符串CollectionsIO序列化,规则表达式System.Text.RegularExpressions,议题介绍,规则表达式 (Regular Expressions),支持匹配和替换的能力匹配 This example is a matchRegex.IsMatch(“Acme Corp.”,”.*e.*p”)替换 this example changes all in all to any in anyRegex.Replace(all in all, (?w)k, ny),规则表达式 (Regular Expressions)支持匹,规则表达式 (Regul

9、ar Expressions),执行模式解释Regex re = new Regex(“.*e.*n”)re.IsMatch(“Acme Corporation”)编译Regex re = new Regex(“.*e.*n”, RegexOptions.Compiled)Compiled form is expensive to create只能被用于静态,规则表达式 (Regular Expressions)执行模,议题,介绍基本数据类型字符串规则表达式IO序列化,CollectionsSystem.Collections,议题介绍,Collections接口模型,基于模型的接口IColl

10、ection枚举,转化成数组,同步的,只读IList, IDictionary源自ICollection增加,清除,包含,移出IList操纵一个连续有序的值,IndexOf, Insert, RemoveAtIDictionary处理一个键值对的集,Collections接口模型基于模型的接口,Collections,.NET Framework 提供一些通用的 collectionsStack, Queue (ICollection)Array, ArrayList (IList)Hashtable (IDictionary)使用一个ArrayList (IList)list5=“My st

11、ring data”;String s = (String)list5;使用一个 Hashtable (IDictionary)tableMyDataKey = MyDataObject;Data dataObj = (Data)tableMyDataKey;,Collections.NET Framework 提供一些,Collections枚举,所有的 collections support getting an IEnumeratorEnumerators can be strongly typed简单Dim b As ButtonFor Each b in MyButtonList C

12、onsole.WriteLine(b)Next b枚举的性能非常出色,Collections枚举所有的 collections,Strongly Typed Collections,Treat generically by interface or specifically by typePrivate interface implementation enables strongly-typed collectionspublic class ButtonList : IList public int Add(Button button)int IList.Add(Object obj)St

13、rong-typing provides type-checking, and self-documentationAlthough you can implement ICollection, inheriting CollectionBase is also an option,Strongly Typed CollectionsTrea,Collections: StrongTyping,ButtonList,WidgetList,IList,IList,int Add (Button b),int Add (Object o),int Add (Widget w),int Add (O

14、bject o),Collections: StrongTypingButto,Collections,Collections,议题,介绍基本数据类型字符串规则表达式Collections序列化,IOSystem.IO,议题介绍,IO 流,读取和写字节不需要任何关于指定数据类型的知识Stream基本类库可编辑流模式无缝增加缓存, 管道, 加密方法,同步和异步的支持必须实现同步支持,异步是自动的,IO 流读取和写字节,IO 读和写,Most common point of contact with IO使用Streams读和写用户类型Knowledge of stream data format

15、 as appropriate.NET Framework 支持 BinaryReader/Writer 和 StreamReader/WriterStreamReader/Writer理解编码,IO 读和写Most common point of con,IO 例子写到文件,/ 在写模式下打开一个FileStream并且包装他到一个StreamWriterStreamWriter writer = File.CreateText(“C:TempFoo.Bar”);/ 写一个String和一个double,这些在Stream上将会作为UTF8编码文本writer.WriteLine(“Hell

16、o, World!”);writer.WriteLine(3.1415926535);/ 关闭StreamWriter和下面的Streamwriter.Close();,IO 例子写到文件/ 在写模式下打开一个FileStre,File.Copy( String, String )Directory.Delete( String ),IO 文件和目录,Path.GetFullPath ( String ),文件和目录的操纵分成:FileInfo/DirectoryInfo, 文件和目录的操纵的例子File/Directory,静态操纵文件和目录的操纵的例子Path, 静态操纵路径,FileIn

17、fo.CopyTo( String )DirectoryInfo.Delete( ),IO 文件和目录文件和目录的操纵分成:,序列化System.Runtime.Serialization,议题,介绍基本数据类型字符串规则表达式CollectionsIO,议题介绍,序列化 (Serialization),存储一个对象的图表到一个stream中以备后来的重新实例化完全自动化系统跟踪和恢复对象数据并且在对象之间连接支持所有的对象类型ISerializable允许用户控制可插入格式器架构定义你自己的格式,序列化 (Serialization)存储一个对象的图表到一,序列化ISerializable

18、对默认的序列化,下列情况使用默认序列化:A class can be serialized as isNo specific process needs to occur for serialization/deserializationYou can easily mark items not to be serialized using the NonSerializedAttribute下列情况实现ISerializable:对象需要控制他们自己的序列化,序列化ISerializable 对默认的序列化下列情况使,序列化代码例子,非序列化Dim s As Stream reopen th

19、e serialized fileDim sf As SoapFormatter = New SoapFormatterDim al As ArrayList = CType(sf.Deserialize(s), ArrayList),序列化Dim s As Stream open and create a file to serialize alsoDim sf As SoapFormatter = New SoapFormatterDim al As New ArrayList populate with objectssf.Serialize(s, al) after processing, close the stream,序列化代码例子非序列化序列化,串行化,This demonstration shows how to use serialization to store an object graph to file, and easily deserialize it later,串行化This demonstration shows ho,资源,MSDNhttp:/ Framework 讨论组列表http:/Gotdotnethttp:/,资源MSDN,提问与回答?,提问与回答?,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号