您好,欢迎访问一九零五行业门户网

C#中如何检查字符串数组中是否包含字符串数组中的特定工作?

in c#, string.contains() is a string method. this method is used to check whether the substring occurs within a given string or not.
it returns the boolean value. if substring exists in string or value is the empty string (“”), then it returns true, otherwise returns false.
exception − this method can give argumentnullexception if str is null.
this method performs the case-sensitive checking. the search will always begin from the first character position of the string and continues until the last character position.
example 1contains is case sensitive if the string is found it return true else false
static void main(string[] args){ string[] strs = { "sachin", "india", "bangalore", "karnataka", "delhi" }; if (strs.contains("sachin")){ system.console.writeline("string present"); } else { system.console.writeline("string not present"); } console.readline();}
输出string not present
example 2static void main(string[] args){ string[] strs = { "sachin", "india", "bangalore", "karnataka", "delhi" }; if (strs.contains("sachin")){ system.console.writeline("string present"); } else { system.console.writeline("string not present"); } console.readline();}
输出string present
example 3 的中文翻译为:示例 3static void main(string[] args){ string[] strs = { "sachin", "india", "bangalore", "karnataka", "delhi" }; var res = strs.where(x => x == "sachin").firstordefault(); system.console.writeline(res); console.readline();}
输出sachin
example 4的中文翻译为:示例4static void main(string[] args){ string[] strs = { "sachin", "india", "bangalore", "karnataka", "delhi" }; foreach (var item in strs){ if (item == "sachin"){ system.console.writeline("string is present"); } } console.readline();}
输出string is present
以上就是c#中如何检查字符串数组中是否包含字符串数组中的特定工作?的详细内容。
其它类似信息

推荐信息