c# - 将 LINQ 语句从查询转换为流利的 c# 语法

标签 c# .net linq

嘿,我一直在将一个简单的 Linq 语句从查询语法转换为 C# 中的流畅语法。我认为这是可能的,但我需要提示。

from property in target.GetType().GetProperties()
select new
{
   Name = property.Name,
   Value = property.GetValue(target, null)
};

为了..

var props = target.GetType().GetProperties().Select(p=>p.Name.... )

选择后我需要更改什么?

最佳答案

var props = target
    .GetType()
    .GetProperties()
    .Select(p => new { 
        Name = p.Name, 
        Value = p.GetValue(target, null)
});

关于c# - 将 LINQ 语句从查询转换为流利的 c# 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5970055/

相关文章:

c# - 如何选择 'product' 行而不是 'sale' 行

c# - 从aspx调用aspx.cs中的ajax方法

c# - 从 Json 字符串中提取数据

javascript - 如何使用 C# 代码添加 Html Audio 元素

c# - 为什么数组项分配会降低 C# 程序的性能?

c# - 使用 LINQ 根据给定条件过滤 List<Point>

c# - 正则表达式组字符串替换问题

c# - 如何在 C# 中处理 XML

java - 什么是业务流程管理系统?

c# - 为什么在使用 foreach 时不执行此 LINQ 查询?