简体   繁体   中英

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.

它是List<T>类的一种方法

它是List<T>的一部分,它是BCL的一部分。

System.Collections.Generic找到List<T>

The easiest way to find out in VS if you right click on AddRange and select "Go To Definition"

You'll see some variation of this at the top of the Class

#region Assembly mscorlib.dll, v4.0.30319
// C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll
#endregion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM