gpt4 book ai didi

c# - 字符串数组。包含?

转载 作者:IT王子 更新时间:2023-10-29 04:40:38 26 4
gpt4 key购买 nike

.NET 2

string[] myStrings = GetMyStrings();    
string test = "testValue";

如何验证 myStrings 是否包含 test

最佳答案

在 .NET 2.0 中,如果需要索引,可以执行以下操作:

int index = Array.FindIndex(
myStrings,
delegate(string s) { return s.Equals(test); }
);
如果 myStrings 不包含 test

index 将为 -1

如果您只想检查是否存在:

bool exists = Array.Exists(
myStrings,
delegate(string s) { return s.Equals(test); }
);

关于c# - 字符串数组。包含?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3917589/

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