如果我要在同一类型上使用C#typeof调用的结果,是否值得保存该值,或者只是多次调用typeof().对我来说,多种类型是优选的,因为它可以更简洁,可读的代码.我想这取决于编译器是否会"内联"代码?
我正在疯狂地试图理解LINQ中的表达式.非常感谢任何帮助(甚至告诉我,我完全不在这里).
假设我有三节课
public class Person
{
public string Name { get; set;}
public IEnumerable<PersonLocation> Locations { get; set;}
public IEnumerable<PersonEducation> Educations { get; set:}
}
public class PersonLocation
{
public string Name { get; set;}
public string Floor { get; set;}
public string Extension { get; set;}
}
public class PersonEducation
{
public string SchoolName { get; set;}
public string GraduationYear { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个接收字符串的方法,例如Locations.Name或Locations.Floor,或Educations.SchoolName,然后创建一个动态linq查询
IEnumerable<Person> people = GetAllPeople();
GetFilteredResults(people, "Location.Name", "San Francisco");
GetFilteredResults(people, "Location.Floor", "17");
GetFilteredResults(people, "Educations.SchoolName", "Northwestern"); …Run Code Online (Sandbox Code Playgroud)