다음을 통해 공유


Value and Enum Types Technology Sample

Introduces developers to the .NET Framework value and enumerated types, and demonstrates how to create and work with them. The sample derives types from the ValueType and Enum classes. Each of these classes provides features that enable the developer to work with them easily.

For information about using the samples, see the following topics:

To build the sample using the command prompt

  1. Open the Command Prompt window and navigate to one of the language-specific subdirectories under the ValueAndEnumTypes directory.

  2. Type msbuild ValueAndEnumTypesCS.sln or msbuild ValueAndEnumTypesVB.sln, depending on your choice of programming language, at the command line.

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to one of the language-specific subdirectories under the ValueAndEnumTypes directory.

  2. Double-click the ValueAndEnumTypesCS.sln or ValueAndEnumTypesVB.sln file, depending on your choice of programming language, to open the file in Visual Studio.

  3. On the Build menu, click Build Solution.

To run the sample

  1. Navigate to the directory that contains the built executable file.

  2. Type ValueEnum.exe from the command line.

    NoteNote

    This sample builds a console application. You must launch it from a console window to view its output.

Requirements

.NET Framework Version: 2.0, 1.1, 1.0

Remarks

The following bullets briefly describe the classes and technologies used by this sample.

  • Value and Reference Types

    • ValueType All value types are implicitly derived from ValueType.

    • Object All types are implicitly derived from Object. In this sample the GetHashCode() and Equals() virtual methods are overloaded.

  • Enumerated Types

    • Enum All enumerated types are derived from Enum, which implements ToString() and Parse() among other helper methods used in this sample.
  • Custom Attributes

    • FlagsAttribute The FlagsAttribute can be assigned to enumerated types to indicate that the type's members are flag values. The Enum type reflects over its derived types in search of this flag to decide how the ToString() and Parse() methods should behave.

Review comments in the source code files for more information on value and enumerated types.

See Also

Reference

Enum
FlagsAttribute
Object
ValueType

Concepts

Enumerations in the Common Type System
Value Types in the Common Type System

Other Resources

Common Type System
Metadata and Self-Describing Components