gpt4 book ai didi

c# - 用 string[] 做包含的最快方法

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

我正在从第 3 方库取回“string[]”。我想对它做一个包含。最有效的方法是什么?

最佳答案

Array.IndexOf:

bool contains = Array.IndexOf(arr, value) >= 0;

或者只使用 LINQ:

bool contains = arr.Contains(value);

对于大多数用途,LINQ 应该“足够快”。

关于c# - 用 string[] 做包含的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/409236/

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