Shortcut to create properties in Visual Studio?

后端 未结 16 1869
暖寄归人
暖寄归人 2020-12-02 03:42

I have seen some people creating properties in C# really fast, but how did they do it?

What shortcuts are available in Visual Studio (currently using Visual Stu

相关标签:
16条回答
  • 2020-12-02 04:05

    Go to

    Tools >> Options >> Text Editor >> C# >> IntelliSense

    Under the Snippets behaviour section:

    Make sure "Always include snippets" is selected.

    I hope it works for you too.

    0 讨论(0)
  • 2020-12-02 04:06

    When you write in Visual Studio,

    public ServiceTypesEnum Type { get; set; }
    public string TypeString { get { return this.Type.ToString();}}
    

    ReSharper will keep suggesting to convert it to:

    public string TypeString => Type.ToString();
    
    0 讨论(0)
  • 2020-12-02 04:06

    In visual studio 2017 community, the key is ctrl + .

    0 讨论(0)
  • 2020-12-02 04:09

    ReSharper offers property generation in its extensive feature set. (It's not cheap though, unless you're working on an open-source project.)

    0 讨论(0)
  • 2020-12-02 04:12

    I think Alt+R+F is the correct one for creating property from a variable declaration

    0 讨论(0)
  • 2020-12-02 04:14

    In addition to Amra's answer, you can find other snippets by typing

    Ctrl + K, Ctrl + X

    Which is mapped to Edit.InsertSnippet in my Visual Studio and shows you the full list of snippets available.

    Also remember that you can configure your own snippets by using the Snippets Manager, which is available in the Tools menu, Code Snippets Manager.... Basically you create a file *.snippet and use the Import button in the Code Snippets Manager to add it to Visual Studio. For a full tutorial you can go to the docs; Walkthrough: Create a code snippet.


    In Visual Studio Code snippets are handled slightly different than in Visual Studio. You can access all snippets by typing Ctrl + Shift + P and type in snippet. Two options should be available, Insert Snippet and Preferences: Configure User Snippets.

    The former inserts a snippet from your list of snippets (using the Language Mode which you can see in the status bar), and with the latter you can create your own snippets for any Language Mode.

    If you know the shortname you can just type that and use Tab to expand the snippet. For inserting a C# property you have three snippets available, prop, propfull, and propg, for different purposes.

    0 讨论(0)
提交回复
热议问题