我可以在LINQ中声明/使用某些变量吗?还是我可以写下面的LINQ更清晰的文章? [英] Can I declare / use some variable in LINQ? Or can I write following LINQ clearer?

查看:55
本文介绍了我可以在LINQ中声明/使用某些变量吗?还是我可以写下面的LINQ更清晰的文章?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 LINQ 中声明/使用一些变量吗?

Can I declare / use some variable in LINQ?

例如,我可以编写以下LINQ clearer吗?

For example, can I write following LINQ clearer?

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

有没有办法在这里两次不写入/调用t.ComponentType.GetProperty(t.Name)?

Are there ways to not write / call t.ComponentType.GetProperty(t.Name) two times here?

推荐答案

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

这篇关于我可以在LINQ中声明/使用某些变量吗?还是我可以写下面的LINQ更清晰的文章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆