gpt4 book ai didi

c# - 如何检查特定字符串是否不存在于 c# 的列表中?

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:09 25 4
gpt4 key购买 nike

我有一个 list 如下,

List<string> variablelist = new List<string> { "first", "second","third"};

我还有一份 list ,比如
 List<string> method = new List<string>();
//somecode
method.Add(workingline);

我想检查 variablelist 的任何元素不存在于 method 中列表,我也想得到那个特定的元素。

提前致谢

最佳答案

LINQ 是执行此操作的最简单方法,使用 Except 方法:

var inOnlyVariableList = variableList.Except(method).ToList();

结果将是 List<string> variableList 中的字符串但不在 method 中.

关于c# - 如何检查特定字符串是否不存在于 c# 的列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42554717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com