结构

来源:互联网 发布:黄品源 知乎 编辑:程序博客网 时间:2024/04/30 03:46

通常用于较小的数据类型:

eg:using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace 例8_17_结构的使用
{
    class Program
    {
        public struct Employee
        {
            public string name;
            public string sex;
            public int age;
            public string duty;
            public Employee(string n, string s, string a, string d)
            {
                name = n;
                sex = s;
                age = Convert.ToInt32(a);
                duty = d;
            }
            public void Information()
            {
                Console.WriteLine("{0},{1},{2},{3}",name,sex,age,duty);
            }
        }
        static void Main(string[] args)
        {
            Employee employee1=new Employee ("小张","女","25","测试员");
            employee1 .Information();
            Employee employee2;
            employee2.name = "小叶";
            employee2.sex = "男";
            employee2 .age=25;
            employee2.duty="程序员";
            employee2 .Information();
            Console .ReadLine();
        }
    }
}
0 0
原创粉丝点击