标签:get turn 特性 OLE div subject main ati span
public class Teacher { public string Name { get; set; } public string Subject { get; set; } public void Deconstruct(out string name,out string subject) { name = Name; subject = Subject; } } public class Student { public Student(string name,int grade,Teacher teacher) { Name = name; Grade = grade; Teacher = teacher; } public string Name { get; set; } public int Grade { get; set; } public Teacher Teacher { get; set; } public void Deconstruct(out string name, out int grade, out Teacher teacher) { name = Name; grade = Grade; teacher = Teacher; } public bool Is5GradeStudent(Student student) { return student is Student(_, 5, Teacher(_, "物理")); } } static void Main(string[] args) { Student stu = new Student("adsfsa", 5, new Teacher() { Name = "张超", Subject = "物理" }); bool sss= stu.Is5GradeStudent(stu); Console.WriteLine(sss.ToString()); }
还可以这么写
public bool Is5GradeStudent(Student student) { return student is { Grade: 5, Teacher: { Subject: "物理" } }; }
public bool Is5GradeStudent(object obj) { return obj is Student s && s is { Grade: 5, Teacher: { Subject: "物理" } }; }
标签:get turn 特性 OLE div subject main ati span
原文地址:https://www.cnblogs.com/Celebrator/p/12420171.html