When using the default/optional parameters of C #, note that the default values of parameters are automatically added to the caller during compilation.
If I have such a method:
1 public class Name 2 {3 public void Test (Boolean isPass, String name = "") 4 {5 if (String. isNullOrWhiteSpace (name) 6 Console. writeLine ("name is empty. "); 7 else 8 Console. writeLine ("name have value. "); 9} 10}
Use this method in another dll:
1 public void Test () 2 {3 DAL. Name c = new DAL. Name (); 4 c. Test (true); 5}
The caller's final compilation result is:
Public void Test () {Name c = new Name (); c. Test (true ,"");}
We can see that during compilation, our default value is appended to the method caller. Therefore, pay attention to the following:
If our dll is a public build, it is best not to use the default parameter, use the overload method to achieve the effect of different parameters; because the default parameter method is used, if only the dll is re-compiled, if the referenced dll is not re-compiled, an error occurs.