A very small trick is to use the fan type to query whether a string is contained. Sometimes we need to determine whether a variable or another container that stores data contains several strings. For example:
To determine whether the variable A is equal to 123 or 456, we should use if (. equals ("123") |. equals ("456 ")). but I always think this is not easy to write. So I will use the following method.
If you think that writing is not efficient, please point it out to me.
Example:
Using System;
Using System. Configuration;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;
Using System. Collections. Generic;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
List <string> listStr = new List <string> (new string [] {"a", "B "});
If (listStr. Contains ("B "))
{
ScriptManager. RegisterStartupScript (this, typeof (Page), "alert", "alert ('" + listStr [0]. ToString () + "')", true );
}
}
}