One, enumeration.
Enumerations are user-defined integer types. When declaring an enumeration type, you need to specify a set of acceptable instance values that the enumeration can contain.
Let's look at an example.
using System;
using System.Windows;
namespace gosoa.com.cn
{
class MyFirstClass
{
static void Main()
{
int userAage=(int)user.fatherAge;
Console.WriteLine(userAage);
}
public enum user
{
Age=18, //年龄
gread=2, //年级
fatherAge=65 //父亲的年龄
}
}
}
In the example, 65 is output. The public enum user is the enumeration type that declares a user. The Age,gread,fatherage is its three options. Each is endowed with three specific values. int useraage= (int) user.fatherage; This defines a useraage and assigns it a value of user.fatherage, which is 65.
Let's look at a little sample.
static void Main()
{
user userTemp=user.gread;
Console.WriteLine(userTemp.ToString());
}
In this example, the output is the Gread string. Why, then? Because an enumeration is instantiated in the background as a structure derived from System.Enum, this means that it can be invoked to perform some action. The example above is a description.