且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取列表中的项目

更新时间:2023-11-28 16:06:52

使用 C#3.0中的List<T>.Find 方法:

var config = Configurations.Find(item => item.Name == "myConfig");

在C#2.0/.NET 2.0中,您可以使用类似以下的内容(语法可能会略有偏离,因为很长一段时间以来我都没有以这种方式编写委托...):

In C# 2.0 / .NET 2.0 you can use something like the following (syntax could be slightly off as I haven't written delegates in this way in quite a long time...):

Configuration config = Configurations.Find(
    delegate(Configuration item) { return item.Name == "myConfig"; });