c# - 在列表中查找项目的特定关键字

标签 c# .net windows

例如我有一个列表如下:

List<string> myList = new List<string>();

其中包含:

item1
item 2
testing 123

我怎么说:

"where list item contains the value "123" return that item in full"

因此输出结果为:

testing 123

最佳答案

string s = myList.Where(p => p.Contains("123")).SingleOrDefault();

string s = myList.SingleOrDefault(p => p.Contains("123"));

关于c# - 在列表中查找项目的特定关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11950557/

相关文章:

c# - 获取 WebException 错误中的错误编号

c# - 如何在 C# 中从 StreamReader 获取文本

c# - Unity - 拦截 WCF 服务类?

c# - 检查字符串是否代表具有正确格式的完整路径的文件名的最简单方法是什么?

.net - 如何使单个事件处理程序处理ALL Button.Click事件?

windows - Windows 上的 perl : Can't do inplace edit on file: File exists

Windows 等效于 linux cksum 命令

c# - signalR 和 CustomTypeConverter

c# - 在Windows窗体中,当用户单击滚动条时如何阻止UI线程阻塞?

windows - 如何在 Windows 中执行 .r 文件