Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where Can I Find List<T>.AddRange() Method?

I have some old school looking code that is as follows:

IList<KeyValuePair<string, ValuePair>> ServicePairs = new List<KeyValuePair<string, ValuePair>>();
// ...
foreach (KeyValuePair<string, string> Set in Services)
{
    if (string.Format("{0} (Service)", Set.Value) == c.ColumnName)
    {
        ServicePairs.Add(new KeyValuePair<string, ValuePair>(c.Ordinal.ToString(), new ValuePair { Id = Set.Key, Title = Set.Value }));
    }
}

Resharper is suggesting I pretty it up a bit by converting it to the following:

ServicePairs.AddRange(from Set in Services
                      where string.Format("{0} (Service)", Set.Value) == c.ColumnName
                      select new KeyValuePair<string, ValuePair>(
                          c.Ordinal.ToString(),
                          new ValuePair { Id = Set.Key, Title = Set.Value }));

What I'd like to know is - where does this AddRange() method come from - is it from Microsoft Prism or somewhere else?



UPDATE: It's been pointed out that this is part of the List<T> class. Apparently, it's not part of the IList<T> interface, which was the source of my confusion. Thanks everyone.

like image 587
splatto Avatar asked Jan 19 '23 19:01

splatto


1 Answers

It's a method of the List<T> class.

like image 107
Thomas Levesque Avatar answered Jan 28 '23 20:01

Thomas Levesque