Can I declare / use some variable in LINQ? Or can I write following LINQ clearer?

后端 未结 4 1866
长发绾君心
长发绾君心 2020-12-09 01:24

Can I declare / use some variable in LINQ?

For example, can I write following LINQ clearer?

var q = from PropertyDescriptor t in TypeDescriptor.GetPr         


        
4条回答
  •  心在旅途
    2020-12-09 02:04

    Yes, using the let keyword:

    var q = from PropertyDescriptor t in TypeDescriptor.GetProperties(instance)
        let nameProperty = t.ComponentType.GetProperty(t.Name)
        where (nameProperty != null)
        select nameProperty;
    

提交回复
热议问题