Number of constructor classes and number of constructor classes

Source: Internet
Author: User

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 ));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.