Method One: There are several methods to use String. Split (char);//split by char, return string array array.indexof (array,string): Returns the subscript array.lastindexof of the first occurrence of the specified string in the array (array , string): Returns the subscript of the last occurrence of the specified string in the array if there is no match, returns the -1[sample code]:string strnum= "001,003,005,008"; string[] strarray= Strnum.split (', ');//split by comma, split char or char array Console.WriteLine (Array.indexof (Strarray, "004"). ToString ()); Citation: https://www.cnblogs.com/yliang/archive/2013/04/30/3052100.html
Note: Using IList requires using System.Collections;
This method cannot be directly indexof in the array and requires Array.indexof (X,X);
Method two: string[] tt = new string[] {"abc", "TTT", "EFG"};
String t = "TTT";
Return TT. Count (p=>p = = t) > 0//This method is used to return the number of elements that satisfy the condition in the specified sequence three: using arr. Contains (str) method, by using the default equality comparer to determine whether the sequence contains the formulated element. Here is the code I wrote to open a picture. Filter out non-conforming images to prevent errors.
OpenFileDialog dialog = new OpenFileDialog ();
String[] Mys = {". bmp", ". jpg", ". png", ". gif", ". ico"};
if (dialog. ShowDialog () = = DialogResult.OK)
{
String filetype=path.getextension (dialog. FileName);
BOOL A= Mys. Contains (FileType);
if (a)
{
Bitmap P1 = new Bitmap (dialog. FileName);
pictureBox1.Image = p1;
}
Else
{
MessageBox.Show ("The picture format is not supported! ");
}
}
C # Determines whether a string is in another string array