小编Dan*_*rak的帖子

是否值得为多次使用保存typeof()调用的结果?

如果我要在同一类型上使用C#typeof调用的结果,是否值得保存该值,或者只是多次调用typeof().对我来说,多种类型是优选的,因为它可以更简洁,可读的代码.我想这取决于编译器是否会"内联"代码?

.net c# optimization typeof

7
推荐指数
1
解决办法
236
查看次数

LINQ中嵌套的通用Lambda

我正在疯狂地试图理解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)

.net c# linq lambda expression-trees

5
推荐指数
1
解决办法
1118
查看次数

标签 统计

.net ×2

c# ×2

expression-trees ×1

lambda ×1

linq ×1

optimization ×1

typeof ×1