int数组到IEnumerable <MyTestObj>?

Las*_*vik -2 c# linq

我有一个MVC发布一个整数数组,我想将该数组的int转换为IEnumerable<MyTestObj>.怎么做的?好像我不能用myintArr.AsEnumerable().

Meh*_*ari 6

您需要以下内容(取决于您创建对象的方式):

myIntArr.Select(i => new MyTestObj(i));
// or...
myIntArr.Select(i => (MyTestObj)i);
// or...
myIntArr.Select(i => new MyTestObj { SomeProperty = i });
Run Code Online (Sandbox Code Playgroud)