结构体 枚举

结构体属于自定义类型

定义位置在main函数外面 类的里面

定义格式:
struct 自定义名字
{
public 数据类型 名字;
public 数据类型 名字;

集合类型<结构体名称>集合名称=new 集合类型<结构体名称>();

在main函数外面定义一个自定义类型的结构体  在main主函数中使用;

 

二,枚举

 枚举就是将原本不固定的内容变成固定选择结果的内容,就跟填空题变成选择题一样

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

namespace _3_2作业结构体
{
    class Program
    {
        struct student
        {
            public string xuehao;
            public string name;
            public DateTime dt;
            public int cj;


        }

        static void Main(string[] args)
        {
            Console.Write("请输入录入学生的个数");
            int a = Convert.ToInt32( Console.ReadLine());

            List< student >list= new List<student>();
           
            for (int i = 1; i <= a; i++)
            {
                student s = new student();
                Console.Write("请输入第"+i+"个学生的学号:");
                s.xuehao = Console.ReadLine();
                Console.Write("请输入第" + i + "个学生的姓名:");
                s.name = Console.ReadLine();
                Console.Write("请输入第" + i + "个学生的生日:");
                s.dt = Convert.ToDateTime(Console.ReadLine());
                Console.Write("请输入第" + i + "个学生的成绩:");
                s.cj = Convert.ToInt32(Console.ReadLine());

                list.Add(s);
            }
            Console.WriteLine("===================学生信息展示===========================");
            for (int i = 0; i < list.Count; i++)
            {
                for (int j = i+1; j < list.Count;j++ )
                    if (list[i].cj < list[j].cj)
                    {
                        student sss = list[i];
                        list[i] = list[j];
                        list[j] = sss;
                    }
            }
            foreach (student s in list)
            {
                int age = DateTime.Now.Year - s.dt.Year;
                string sr = s.dt.ToString("yyyy年MM月dd日");
                Console.WriteLine(s.xuehao + "\t" + s.name + "\t" +sr + "\t" + age + "\t" + s.cj);
            }
Console.ReadLine(); }
class Program
    {
        enum Sex
        {
            男,女
        }
        enum Week 
        {
            星期一,
            星期二,
            星期三,
            星期四,
            星期五,
            星期六,
            星期日
        
        }
        static void Main(string[] args)
        {
            Sex s = Sex.男;
            Sex sd = Sex.女;

            Week w = Week.星期二;

            Console.ReadLine();
        }

 

posted @ 2017-03-05 16:19  v587yy  阅读(266)  评论(0编辑  收藏  举报