gpt4 book ai didi

c# - 将 Linq 查询转换为 .Net 中的结构

转载 作者:太空狗 更新时间:2023-10-30 00:12:48 24 4
gpt4 key购买 nike

早上好,
我创建了一个结构,作为我已有的类的简化版本。我正在尝试使用 linq 查询来遍历 MyClass 列表并根据结果创建一个列表(一个基于 MyClass 上的一些属性的不连续列表)。像这样的……

List<MyStructure> thisList = (from MyClass thisClass in List<MyClass>
select thisClass.Property1, thisClass.Property2, thisClass.Property3 Distinct.Cast<MyStructure>()).ToList<MyStructure>();

其中 MyStructure 包含 Property1、Property3 和 Property3 3 个相同类型的变量。

我完全知道上面的代码不会编译,但这是我正在尝试做的。有人可以告诉我这是否可行吗?

谢谢

最佳答案

Exactly what you need

这叫做匿名类型。

来自链接: alt text

关于c# - 将 Linq 查询转换为 .Net 中的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2310583/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com