相关疑难解决方法(0)

将匿名类型转换为类

我在List anBook中有一个匿名类型:

var anBook=new []{

new {Code=10, Book ="Harry Potter"},
new {Code=11, Book="James Bond"}
};
Run Code Online (Sandbox Code Playgroud)

是否可以将其转换为具有以下clearBook定义的List:

public class ClearBook
{
  int Code;
  string Book; 
}
Run Code Online (Sandbox Code Playgroud)

通过使用直接转换,即不通过书籍循环?

c# linq anonymous-types

24
推荐指数
3
解决办法
5万
查看次数

标签 统计

anonymous-types ×1

c# ×1

linq ×1