在netcore 1.0中替换array.convertall [英] Replace array.convertall in netcore 1.0
问题描述
我当前的代码是使用Array.ConvertAll,我需要迁移到net core 1.0。如何将其迁移到Net Core中工作。
我尝试过:
我们可以使用带有自定义转换代码的foreach语句来处理转换吗?
但是我不知道怎么做,任何帮助都有所帮助。
My current code is using Array.ConvertAll, which i need to migrate to net core 1.0. How to migrate it to work in Net core.
What I have tried:
Can we use foreach statement with custom conversion code to handle the conversion?
But i dont know how to do it, Any help appreciated.
推荐答案
这是一项非常基本的任务,你要求做的事情。我认为您需要阅读更多编程教程/ C#教程,以充分了解您正在尝试做什么。
关于你能做什么的一个非常基本的想法:
This is an extremely basic task what you are asking to do. I think you need to read more programming tutorials/C# tutorials to full understand what it is you are trying to do.
An extremely basic idea of what you can do:
public class American
{
public string Name { get; set; }
public int Age { get; set; }
}
public class European
{
public string Name { get; set; }
public int Age { get; set; }
}
var a = new American();
a.Name = "Name 1";
a.Age = 44;
var americans = new List<American>();
americans.Add(a);
var europeans = new List<European>();
foreach (var american in americans)
{
var convert = new European();
convert.Name = american.Name;
convert.Age = american.Age;
europeans.Add(convert);
}
//europeans contains your converted americans
有自动装置和什么没有,但鉴于你要求做一些基本的事情,我担心自动化装置可能太混乱了这次。在跳转到更复杂的库之前,您应该学习基础知识。
There are automappers and what not, but given you were asking to do something as basic as this, I am afraid automappers might be too confusing at this time. You should work on the basics before jumping to more complicated libraries.
这篇关于在netcore 1.0中替换array.convertall的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!