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类型,实体类数组,结构体内可以存任何数据,非常好用!
© 版权声明
THE END
暂无评论内容