หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
This code generation applies to:
C#
Visual Basic
What: Lets you immediately generate the code for a class or type.
When: You introduce a new class or type and want to properly declare it, automatically.
Why: You could declare the class or type before using it, however this feature will generate the class or type automatically.
How-to
Place your cursor on the line where there is a red squiggle. The red squiggle indicates a class that doesn't yet exist.
C#:
Visual Basic:
Next, do one of the following:
Keyboard
- Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
Mouse
- Right-click and select the Quick Actions and Refactorings menu.
- Hover over the red squiggle and click the
icon that appears.
- Click the
icon that appears in the left margin if the text cursor is already on the line with the red squiggle.
Select one of the options from the drop-down menu:
- Generate class 'TypeName' in new file—Creates a class named TypeName in a file named TypeName.cs/.vb
- Generate class 'TypeName'—Creates a class named TypeName in the current file.
- Generate nested class 'TypeName'—Creates a class named TypeName nested inside the current class.
- Generate new type...—Creates a new class or struct with all of the properties you specify.
Tip
Use the Preview changes link at the bottom of the preview window to see all of the changes that will be made before making your selection.
If you selected the Generate new type item, the Generate Type dialog box opens. Configure the accessibility, kind, and location of the new type.
Selection Description Access Set the type to have Default, Internal or Public access. Kind This can be set as class or struct. Name This cannot be changed and will be the name you already typed. Project If there are multiple projects in your solution, you can choose where you want the class/struct to live. File Name You can create a new file or you can add the type to an existing file.
The class or struct is created. For C#, a constructor is also created.
C#
Visual Basic