C#结构体(Struct)运用实践出真理

public class Program
    {
        public static MyStruct myStruct;
        public Program()
        {
            
        }
        public class Student
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public int Age { get; set; }
        }
        /// <summary>
        /// 结构体
        /// </summary>
        public struct MyStruct
        {
            public int Num;
            public string ClassName;
            public Student[] students;
            public string Name;
        }
        public static void Main(string[] args)
        {
            Student[] students = new Student[2];
            students[0] = new Student() { Id = 1, Name = "RongDa", Age = 23 };
            students[1] = new Student() { Id = 1, Name = "MLR", Age = 24 };
            myStruct.students = students;
            myStruct.ClassName = "高三四班";
            string name = "MLR";
            myStruct.Name = name;
            var a = myStruct.students.FirstOrDefault(t => t.Name == myStruct.Name).Age.ToString(); //查询荣达的年龄
            Console.WriteLine(a);
            Console.ReadLine();
            Console.ReadKey();
        }
    }

结构体里定义了int类型,string类型,实体类数组,结构体内可以存任何数据,非常好用!

相关推荐: Mysql查询最近登录的5个用户数据

private static UserModel ConvertToUserModel(userRow row) { if (row == null) return null; UserModel data = new UserModel() { ID = r…


© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容