Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 3-Oct-16 4:45am
v3

1 solution

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:

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900