Use the new functions of common classes in. NET Framework in version 2.0

Source: Internet
Author: User

Zheng Zuo 2005-8-6

In the previous articleBrowse. NET Framework 2.0Common features added in the Type LibraryIn this article, I mainly list several new frequently-used main parts. As a summary, this article is mainly used for some common class extensions.C #2.0Some of the new features found during the time, please correct them if they are inappropriate.

 

1.ExceptionException base class

In2.0,ExceptionAdded the base class.DataProperties. The prototype is as follows:,

Public Virtual idictionary data {Get ;}

It can be seen thatIdictionaryInterface to store abnormal custom information.Predictionmanagement BlockAdded through inheritanceNamevaluecollectionClass member to makeBaseapplicationexceptionWith this function,ExceptionNewDataWhy is the property inspired?

 

2.FileAdded the decryption and encryption function.

UseFileTo protect files. InWindows2003In the View tab of the folder option menu in the System window, the encrypted or compressedNTFSFile check box (inXPOr2000The system should also have related options), you can see that the color of the encrypted file will be different.

The specific method is defined as follows,

Public static void encrypt (String Path );//Encryption

Public static void decrypt (String Path );//Decryption

After encryption, the file turns green. If the file is not authorized to other users, the file cannot be accessed when other users log on. Click the encrypted file attribute to obtain more encrypted information.

 

3.DriveinfoClass

DriveinfoClass to provide system drive information, is. NET 2.0You can use

Driveinfo [] drivers = driveinfo. getdrives ();

Get the driver information, such:

Availablefreespace

Indicates the amount of available free space on a drive.(Disk Quota taken into account)

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.

 

The aboveVolumelabelIt can be read and written, and other attributes are read-only. Generally, you must first determineIsreadyWhether the property isTrue,If it is not ready, access to other properties will be abnormal, and you need to pay attention to whether you have access permissions during programming.

DrivetypeEnumeration is also in. NET 2.0Added under,

Member name

Description

CDROM

The drive is a cd rom device.

Fixed

The drive is a fixed disk.(Fixed Disk Drive)

Network

The drive is a network drive.(Network drive)

Norootdirectory

The drive does not have a root directory.(Drive without root directory)

Ram

The drive is a RAM disk.(RamFlash)

Removable

The drive is a removable storage device.(Removable storage device)

Unknown

The type of drive is unknown.(Unknown device type)

In1.1Used in versionDirectory. getlogicaldrives ();To obtain the drive. UseWMIYou can also implement all the above functions.

 

4.System. Windows. Forms. MenuClass

In2.0AddedTagProperty to inherit from itMenuitemThis attribute is included, just likeTreenode. TagProperties can save various objects.

 

5.ConsoleClass is obviously enhanced

ConsystemicMany functions are added, including setting the appearance and color of the console form, setting and moving the cursor inside, setting the buffer, and checking whether the specific keys on the keyboard are enabled. For exampleConsole. readkey ()And its overload method will be very useful.

 

The above features are. NET Framework 2.0 Beta 2It may be changed after the official version is released.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.