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 1
Contains 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(); }登录后复制