在哪里可以找到 List.AddRange() 方法?
我有一些看起来很旧的代码,如下所示:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它是
List
的一种方法 类。It's a method of the
List<T>
class.它是
List
的一部分是 BCL 的一部分。Its part of
List<T>
which is part of the BCL.System.Collections.Generic
iirc 中的List
。List<T>
inSystem.Collections.Generic
iirc.在 VS 中查找的最简单方法是右键单击 AddRange 并选择“转到定义”,
您将在类的顶部看到一些变化
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