gpt4 book ai didi

C# 如果项目不在数组中

转载 作者:太空狗 更新时间:2023-10-29 23:55:31 25 4
gpt4 key购买 nike

我有一个包含这 3 个项目的数组:

string[] departmentArray = {
"Warranty Service Representative",
"Warranty Service Administrative Manager",
"Warranty and Site Administrator"
};

我有这个字符串

var department = "Warranty Service Representative"

我有这个条件,假设要测试字符串 department 是否不在 departmentArray

if (Array.Exists(departmentArray, element => element != department)){
}

很明显字符串在数组中,所以它应该返回 false,但这对我的字符串返回 true。我做错了什么?

最佳答案

这不是更简单吗?

string[] departmentArray = { 
"Warranty Service Representative",
"Warranty Service Administrative Manager",
"Warranty and Site Administrator" };

String department = "Warranty Service Representative";

if (departmentArray.Contains(department) == false)
{
}

关于C# 如果项目不在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35023031/

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