How to use the vs.net generation method of tips

zhaozj2021-02-17  52

This article mainly facing beginners, introduces how to use VS.NET to generate methods, attributes, indexes, etc.

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

Click on "onestoa" under the class view. As shown below:

Right-click "AddBBS" -> Select Add, add the following to include several four items -> Add Method Add Property Add Field Add Indector as shown in Figure: Click "Add Method" -

Method Access, return 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, Generate Code: Public Static Void Add ()

{

}

Select Method Modifier -> Virtual, Generating Code: Public Virtual Void Add ()

{

}

Select Method Modifier -> External, Generate Code:

Public override void add ()

{

}

Of course, you can also choose two modifiers at the same time. This will not explain it.

How to add an attribute? Click "Add Properties" -> Generate Dialog -> Accessor -> Get, Set, Get / Set -> Select to get this, generate code only read properties. -> Select setting this, generating code only written attributes. -> Select Get / Set, Generate Code Read, and write properties have.

If you want to get read-only properties, choose "Get" Public Int A

{

get

{

Return 0;

}

}

If you just want to get a write property to select "Settings":

Public Int a

{

set

{

}

}

If you want to get read, write properties, choose Get / Settings: Public INT C

{

get

{

Return 0;

}

set

{

}

}

How to add a field? Right-click "Add Field" -> Select Field Modifier -> Constant -> Generate Code:

Public const INT B = 23424234;

The VS.NET also supports the generation of the indexer, the indexer allows an instance of the class or structure to index in the same manner as the array. Indexes are similar to attributes, and different are their accessors using parameters, specific reference MSDN.

Add Method: Right-click "Add Indexer". After easy setting, you can quickly generate the following code:

Public int this [Int A, Int B]

{

get

{

Return 0;

}

set

{

}

}

Ok, let's introduce these, the advantages of using the above methods are not easy to generate errors :) Of course, the above methods are for reference only, beginners should also write some programs to improve their own level.

This article mainly facing beginners, introduces how to use VS.NET to generate methods, attributes, indexes, etc. First, open vs.net. Create a new project. Click on the view -> Select Class View Click "Onstoa" under the class view. As shown below:

Right-click "AddBBS" -> Select Add, add the following to include several four items -> Add Method Add Property Add Field Add Indector as shown in Figure: Click "Add Method" -

Method Access, return 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, Generate Code: Public Static Void Add () {} Select Method Modifier -> Virtual, Generating Code: Public Virtual Void Add () {} Select Method Modifier -> External, Generating Code: Public Override Void Add () {} Of course, you can also choose two modifiers at the same time. This will not explain it. How to add an attribute? Click "Add Properties" -> Generate Dialog -> Accessor -> Get, Set, Get / Set -> Select to get this, generate code only read properties. -> Select setting this, generating code only written attributes. -> Select Get / Set, Generate Code Read, and write properties have. If you want to get read-only properties, select "Get" public int a {get {return 0;}} If you just want to get write properties Select "Settings": public int a {set {}} If you want to get read, write properties, select "Get / Set": Public INT C {Get {Return 0;} set {}}

转载请注明原文地址:https://www.9cbs.com/read-29058.html

New Post(0)