Using constructors to pass values in 20150214-winform

Source: Internet
Author: User

Constructor, a function method that executes when the function is initialized, after a class is created, the system automatically generates a function in this class that is the same as the class name, containing only one sentence of code:

InitializeComponent ();

Create a new function with the same name, and then use a parameter that already forms another overloaded method of this function, which can be any type, string,int, or even a class created by itself, such as the parameters of the newly created constructor in the following code, which are parameters of the class that you create. The value of the transfer is mainly used to transmit the user's login path information.

namespace dati_150128{    publicpartialclass  zhuce_form:form    {          public zhuce_form ()        {            InitializeComponent ();        }        Denglu_class DL1; // Pass Value         Public zhuce_form (denglu_class dl2)        {            InitializeComponent ();             = dl2;}}    }

When passing a value, you need to define a new variable outside the constructor to receive the passed value, which must be of the same type as the value passed. Then in the constructor, let the newly defined parameter point to the passed argument.

Note: in which class or form you need to use the pass-through value, you define the overloaded method of the constructor in that class or form.

Take parameters into the form or class when it is initialized, such as the following code (the parameter assignment process is not given):

       New Denglu_class (); //need to pass the type that is worth the argument, here is a class that you create yourself, 
           // Register button        Private void Denglu_bt_zhuce_click (object  sender, EventArgs e)        {            new Zhuce_form (DL); // bring in Parameters,             zhuce. Show ();        }

After initializing the Parameter object, assign a value to the parameter, and then bring the parameter in when the class or form is initialized, to complete the pass-through value.

Using constructors to pass values in 20150214-winform

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.