Number of constructor classes and number of constructor classes
Number of constructor classes. The class contains multiple overloaded constructor classes. In Microsoft's MSDN, The http://msdn.microsoft.com/en-us/library/h93ya84h (v = vs.110). aspx she found only one constructor with parameters. If there are multiple reloads, how does one get reflected?
Some netizens asked this question yesterday.
At the beginning, Insus. NET was not written successfully. After trying the following method, the constructor first reflected the integer parameter:
Debug, you can see its details:
Below is the second constructor of debug, whose parameter data type is string:
C # There are parameter reflection, creation class, and class constructor parameters passed in.
Assembly asm = Assembly. GetExecutingAssembly ();
// Create an object
Object [] parameters = new Object [2]; // defines the parameters required by the constructor. All parameters must be
Parameters [0] = 3;
Parameters [1] = 5;
Object obj = asm. CreateInstance ("namespace. Class Name", true, System. Reflection. BindingFlags. Default,
Null, parameters, null, null );
For more information, see the description of the Createinstance overload function ..
How to Use the JAVA reflection mechanism to instance a class with parameters in the constructor?
String str1 = "abc ";
Constructor con = String. class. getConstructor (String. class );
System. out. println (con. newInstance (str1 ));