Search code examples
c#ilist

Using a IList, how to populate it via a comma separated list of ID's


I have a property IList CategoryIDs, and a private string variable that contains a comma separated list, how to elegantly populate the IList collection?

I asked earler and I learn a neat way of populating the List with .AddRange(...), but now I realized I have to have the property return IList which doesn't seem to support the .AddRange method.


Solution

  • public IList CategoryIDs
    {
        get
        {
            return list.Split(',')
                    .ToList<string>()
                    .ConvertAll<int>(new Converter<string, int>(s => int.Parse(s)));
        }
    }