Tips on how to use the Vs.net generation method

Source: Internet
Author: User
Tags arrays constant include modifier modifiers reference
Tips This article mainly for beginners, describes how to use the functions provided by vs.net to generate methods, attributes, indexes and so on.

First, open the vs.net. Create a new project. Click View-> Select Class View

Click on "Onestoa" under Class View. The following figure:




Right-click the "Addbbs"-> select Add, add the following include several four-> add a property add a field indexer as shown: Click Add Method-
Method access, rebate type, modifier, parameter type can be selected by Drop-down list box.



Generate the following code: public void Add (int x)



{



}

Select method modifier-> static, generating code: public static void Add ()

{



}

Select method modifier-> virtual, generating code: Public virtual void Add ()

{



}



Select the method modifier-> external to generate code:

public override void Add ()

{



}

Of course, you can also select two modifiers at the same time. This will not be explained.

How do I add a property? Click on the "Add Property"-> Generate dialog-> accessor-> get, set, get/Set-> Select Get this, generate code only read properties. -> Select Set this to generate code only write properties. -> Select Get/set, generate code read, write properties have.

To get a read-only property, select ' Get ' public int a

{

Get

{

return 0;

}

}

To select settings only if you want to get the Write property:

public int A

{

Set

{

}

}

To get read and write properties, select Get/set: public int C

{

Get

{

return 0;

}

Set

{

}

}

How do I add a field? Right-click the Add field-> select field Modifier-> constant-> Generate code:

public const int b = 23424234;

Vs.net also supports the production of indexers, which allow instances of classes or structs to be indexed in the same way as arrays. Indexers are similar to properties, and their accessors take parameters, specifically to MSDN.

Add method: Right-click Add Indexer, after a simple setup, you can quickly generate the following code:

public int this[int A, int b]

{

Get

{

return 0;

}

Set

{

}

}

Well, simply introduce these, the advantages of using the above method is not easy to produce errors: Of course, the above method is for reference only, beginners should also through their own hands to write some procedures to improve their own level.

This article is mainly for beginners, and describes how to use the functions provided by vs.net to generate methods, attributes, indexes, and so on.

First, open the vs.net. Create a new project. Click View-> Select Class View

Click on "Onestoa" under Class View. The following figure:




Right-click the "Addbbs"-> select Add, add the following include several four-> add a property add a field indexer as shown: Click Add Method-
Method access, rebate type, modifier, parameter type can be selected by Drop-down list box.



Generate the following code: public void Add (int x)



{



}

Select method modifier-> static, generating code: public static void Add ()

{



}

Select method modifier-> virtual, generating code: Public virtual void Add ()

{



}



Select the method modifier-> external to generate code:

public override void Add ()

{



}

Of course, you can also select two modifiers at the same time. This will not be explained.

How do I add a property? Click on the "Add Property"-> Generate dialog-> accessor-> get, set, get/Set-> Select Get this, generate code only read properties. -> Select Set this to generate code only write properties. -> Select Get/set, generate code read, write properties have.

To get a read-only property, select ' Get ' public int a

{

Get

{

return 0;

}

}

To select settings only if you want to get the Write property:

public int A

{

Set

{

}

}

To get read and write properties, select Get/set: public int C

{

Get

{

return 0;

}

Set

{

}

}

How do I add a field? Right-click the Add field-> select field Modifier-> constant-> Generate code:

public const int b = 23424234;

Vs.net also supports the production of indexers, which allow instances of classes or structs to be indexed in the same way as arrays. Indexers are similar to properties, and their accessors take parameters, specifically to MSDN.

Add method: Right-click Add Indexer, after a simple setup, you can quickly generate the following code:

public int this[int A, int b]

{

Get

{

return 0;

}

Set

{

}

}

Well, simply introduce these, the advantages of using the above method is not easy to produce errors: Of course, the above method is for reference only, beginners should also through their own hands to write some procedures to improve their own level.




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.