在哪里可以找到 List.AddRange() 方法?

发布于 2024-11-06 04:39:27 字数 1162 浏览 5 评论 0原文

我有一些看起来很旧的代码,如下所示:

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 建议我通过将其转换为以下内容来对其进行一些修饰:

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 }));

我想知道的是 - 这个 AddRange() 在哪里方法来自 - 是来自 Microsoft Prism 还是其他地方?



更新:有人指出,这是 List 类的一部分。显然,它不是 IList 接口的一部分,这是我困惑的根源。谢谢大家。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

じее 2024-11-13 04:39:27

它是 List的一部分是 BCL 的一部分。

Its part of List<T> which is part of the BCL.

煮酒 2024-11-13 04:39:27

System.Collections.Generic iirc 中的 List

List<T> in System.Collections.Generic iirc.

池木 2024-11-13 04:39:27

在 VS 中查找的最简单方法是右键单击 AddRange 并选择“转到定义”,

您将在类的顶部看到一些变化

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文