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.

Jose Cancel
  • 151
  • 1
  • 2
  • 15
  • 1
    Maybe it would be better if you told us what you are *really* trying to do. A Dictionary might be a better choice. – LarsTech Mar 03 '16 at 23:56
  • @LarsTech This is what I"m really trying to do: http://stackoverflow.com/questions/35782580/creating-class-instances-based-on-dynamic-item-lists .But If I figure this out I would be able to do it. – Jose Cancel Mar 03 '16 at 23:59
  • @BJMyers How is this in any way a duplicate of http://stackoverflow.com/questions/30461640/how-do-i-disable-c-sharp-6-support-in-visual-studio-2015? Are you just spamming that? – Jose Cancel Mar 04 '16 at 00:02
  • Sorry about that - I didn't intend to flag this as a duplicate. Must have hit the wrong button. – BJ Myers Mar 04 '16 at 00:12

0 Answers0