1 Nature of the error:
Object a;//a is null
protected void Page_Load (object sender, EventArgs e)
{
A.tostring ();//method that invokes a null object
}
The result is as follows:
It's not easy to write this kind of code in such a stark way, usually more inclined to the following:
2: Error of the usual nature:
Example 1: A function that filters certain characters:
public static string FilterValue (string value)
{
string[] Filterchar = new string[] {"\" ",", "," > "," < "," = ","; "," \ "", "--"};
for (int i = 0; i < filterchar.length; i++)
{
Value = value. Replace (Filterchar[i], "");
}
return value. Trim (');
}
This function, for example, is easy to see: If value is passed in as null, it is equal to Null.replace being called, and the above error occurs.
Therefore, usually, in the first line of the function, the value will be: if (!string. IsNullOrEmpty (value)) a moment.
Example 2: Again, a generic invocation error, binding, Eval ("field"), this method is more common, some cases to go to the string comparison, here is an example:
<%# Eval ("field"). ToString () = = "1"? " Yes ":" No "%>
When eval ("field") is null, a null.tostring () will inevitably appear with the error above, what happens?
1: The value of the field is null
2: Empty data row, that is, your table row of data are not, all is null.
So the precautionary wording is:
<%# convert.tostring (Eval ("field")) = = "1"? " Yes ":" No "%
See this exception: A null object invokes a method (property or other member) into a null.xxx throw. of Course, the scene of this anomaly, that is thousands, the number is not complete, but the essence is the same.
Object reference not set to an instance of an object