.NET Framework 2.0特征详细使用说明手册

开发 后端
.NET Framework 2.0特征比较突出,比如:Exception异常基类;File增加解密加密功能;DriveInfo类;System.Windows.Forms.Menu类;Console类明显得到增强等等。

.NET Framework 2.0的发布为开发人员提供了许多新的功能。我们在这里就会为大家详细介绍一下.NET Framework 2.0特征的使用方法,希望能帮助大家方便理解.NET Framework 2.0版本中的性能。#t#

.NET Framework 2.0特征1.Exception异常基类

在2.0下,Exception基类增加了Data属性,原型如下,

public virtual IDictionary Data {get;}

可见其实现了IDictionary接口,用来存储异常的自定义信息,由此想到在ExceptionManagement block中通过继承增加NameValueCollection类成员来使BaseApplicationException具有该项功能,Exception新增Data属性的灵感来源于此?

.NET Framework 2.0特征2.File增加解密加密功能

使用File的新增加密解密方法来保护文件。在windows2003系统窗口的文件夹选项菜单的查看选项卡中选中用彩色显示加密或压缩的NTFS文件复选框(在xp或2000系统里应该也有相关的选项)就可以看到被加密的文件颜色会不一样。

具体方法定义如下,

public static void Encrypt( string path ); //加密

public static void Decrypt( string path );//解密

加密后,文件就会变成绿色,如果该文件没有授权给其他用户,那在其他用户登录时就无法访问该文件。点击加密文件属性可以得到加密的更多信息。

.NET Framework 2.0特征3.DriveInfo类

DriveInfo类提供系统驱动器的信息,是.net 2.0下新增的类,可以通过

DriveInfo[] drivers = DriveInfo.GetDrives();

得到驱动信息,如:

AvailableFreeSpace
Indicates the amount of available free space on a drive.(磁盘配额考虑在内)

DriveFormat
Gets the name of the file system, such as NTFS or FAT32.

DriveType
Gets the drive type.

IsReady
Gets information on whether or not the drive is ready.

Name
Gets the name of the drive.

RootDirectory
Gets the root directory of the drive.

TotalFreeSpace
Gets the total amount of free space available on a drive.

TotalSize
Gets the total size of storage space on the drive.

VolumeLabel
Gets and sets the volume label of the drive.

上面的VolumeLabel是可读写的,其他属性是只读的。在使用时一般需先判断IsReady属性是否为True,如果没有准备好,那访问其他属性就会发生异常,还有需要注意在编程时是否有权限访问。

DriveType枚举也是在.net 2.0下新增的,

Member name
Description

CDRom
The drive is a CD ROM device.

Fixed
The drive is a fixed disk.(固定磁盘驱动器)

Network
The drive is a network drive.(网络驱动器)

NoRootDirectory
The drive does not have a root directory.(不含根目录的驱动器)

Ram
The drive is a RAM disk.(RAM闪存)

Removable
The drive is a removable storage device.(可移动存储设备)

Unknown
The type of drive is unknown.(未知设备类型)

在1.1版中使用Directory.GetLogicalDrives();来得到驱动器。当然使用WMI也可以实现上述所有功能。

.NET Framework 2.0特征4.System.Windows.Forms.Menu类

在2.0中增加了Tag属性,这样从它继承的MenuItem也就包含了该属性,就像TreeNode.Tag属性可以保存各种对象。

.NET Framework 2.0特征5.Console类明显得到增强

Consle增加了很多功能,包括设置控制台窗体的外观大小和颜色,还可以设置、移动里面的光标,设置缓冲区,判断键盘的那些特定键是否开启等等。举个例子像Console.ReadKey ()以及它的重载方法将会很有用。

 

以上特征是我针对.net framework 2.0 Beta 2来写的,在正式版出来后也许会有些改动。

责任编辑:曹凯 来源: 博客园
相关推荐

2009-12-15 15:13:07

.NET Framew

2009-12-10 17:11:14

.NET Framew

2009-12-18 15:11:50

ADO.NET类

2009-12-22 16:03:34

ADO.NET Ent

2009-12-21 14:55:49

ADO.NET类库

2020-06-28 09:03:26

Linuxtree命令目录

2009-12-14 10:19:23

.NET Framew

2010-01-05 11:26:27

.net Framew

2009-12-22 15:47:03

WCF服务器证书

2009-12-31 09:42:41

ADO对象模型

2009-12-18 14:20:26

ADO.NET组件

2009-12-10 17:47:01

ASP.NET 2.0

2009-12-18 13:52:39

ADO.NET设计器

2009-12-22 10:43:48

ADO.NET类库

2009-12-21 14:55:49

ADO.NET对象

2010-01-06 16:53:57

JS两种语法

2009-12-15 11:28:34

.NET Framew

2009-12-24 09:14:52

ADO.Net Tea

2010-01-12 13:43:30

VB.NET字符转换

2009-12-18 17:06:37

ADO.NET 数据库
点赞
收藏

51CTO技术栈公众号