C enumeration type and structure type instance resolution
- 2020-06-23 01:50:13
- OfStack
This paper takes C# as an example to explain the usage of enumeration type and structure type. The program mainly demonstrates the usage of enumeration type and structure type through personal phone book. The specific code is as follows:
using System;
class ID
{
// Define enumerated types
public enum Sex
{
male, female
};// Make sure you don't forget the semicolon here
// Defines the structure type of the phone book
public struct TelBook
{
public string name;
public Sex sex;// The gender type is an enumerated type
public string number;
}
// every 1 Lines of print 1 Bit user's phone book information
public static void TelPrint( TelBook Someone )
{
Console.Write( Someone.name + "\t");
Console.Write( Someone.sex + "\t");
Console.Write( Someone.number + "\r\n");
}
public static void Main()
{
TelBook Joey, Rose;// The statement TelBook Structure type two user Joey and Rose
Joey.name= "Joey"; // Initialize the Joey Phone book information
Joey.sex= Sex.male;
Joey.number = "84113128";
Rose.name = "Rose";// Initialize the Rose Phone book information
Rose.sex = Sex.female;
Rose.number = "84117456";
TelPrint ( Joey ); // Print the phone book for two users
TelPrint ( Rose );
}
}