码迷,mamicode.com
首页 > Windows程序 > 详细

26.C#--枚举和结构的简单使用

时间:2019-04-23 14:26:11      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:name   类型   枚举类   enum   声明   []   --   rgs   姓名   

namespace _26枚举和结构使用
{
//声明一个枚举类型
public enum Gender
{
男,

}
//声明一个结构类型
public struct Person
{
public string _name;
public int _age;
public Gender _gender;
}
class Program
{
static void Main(string[] args)
{
//定义一个结构类型Person,有三个成员,分别为姓名,性别,年龄 性别用枚举类型
//声明两个Person类型的变量,分别表示 张三 男 18岁/ 小雪 女 16岁
Person zsPerson;
zsPerson._name = "张三";
zsPerson._age = 18;
zsPerson._gender = Gender.男; //注意:枚举这里是用Gender点出男或女

        Person xxPerson;
        xxPerson._name = "小雪";
        xxPerson._age = 16;
        xxPerson._gender = Gender.女;

        Console.WriteLine("{0}今年{1}岁,性别{2}", zsPerson._name, zsPerson._age, zsPerson._gender);
        Console.WriteLine("{0}今年{1}岁,性别{2}", xxPerson._name, xxPerson._age, xxPerson._gender);

        Console.ReadKey();
    }
}

}

26.C#--枚举和结构的简单使用

标签:name   类型   枚举类   enum   声明   []   --   rgs   姓名   

原文地址:https://blog.51cto.com/12679593/2383214

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!