0

I currently have multiple lists and I wish to dynamically create class instances based on the data in this lists.

The class is as fallows:

public class itemFav
{
    public string FavsGTS { get; set; }
    public string FavsGPICS { get; set; }
    public string FavsRNS { get; set; }
    public string FavsPIS { get; set; }
    public string FavsIsOns { get; set; }

}

I'm not sure if it's possible or how its properly done, but I wish to do something like this:

public int itemCount { get; set; }
public dynamic items = new List<dynamic>();

foreach(string item in list1)
{
    itemCount = 0 + items.Count;

    //Here it would create the instances. 
    itemFav instance+itemCount = new itemFav()
    {
        FavsGTS = list1[itemCount],
        FavsGPICS = list2[itemCount],
        FavsRNS = list3[itemCount],
        FavsPIS = list4[itemCount],
        FavsIsOns = list5[itemCount]
    }; 

    items.Add(instance+itemCount);
}

The instance+itemCount is what I would like to know if there is a way to do. Or what is the correct way to dynamically create class instances.

4
  • 1
    Maybe it would be better if you told us what you are really trying to do. A Dictionary might be a better choice. Commented Mar 3, 2016 at 23:56
  • @LarsTech This is what I"m really trying to do: stackoverflow.com/questions/35782580/… .But If I figure this out I would be able to do it. Commented Mar 3, 2016 at 23:59
  • @BJMyers How is this in any way a duplicate of stackoverflow.com/questions/30461640/…? Are you just spamming that? Commented Mar 4, 2016 at 0:02
  • Sorry about that - I didn't intend to flag this as a duplicate. Must have hit the wrong button. Commented Mar 4, 2016 at 0:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.