简体   繁体   中英

Auto List out properties of a class

Say you have a class:

class Bob
{
    public int Something { get;set; }
    public int Something2 { get; set; }
    public int Something3 { get; set; }
}

when you go to create a new instance of Bob:

Bob bob = new Bob {
    Something = 1,
    // Is there a way to automatically write out all properties rather than having to know what they were to type them out?
}

Is there a way to automatically write out all properties rather than having to know what they were to type them out? so Visual Studio 2013 might end up doing this for you so you know what to fill out:

   Bob bob = new Bob {
        Something = ,
        Something2 = ,
        Something3 =
    }

Either Visual Studios own Intellisense or R# will suggest the properties if you press Ctrl-Space or whatever your shortcut to Intellisense is. The feature is intelligent enough to only suggest those you did not already assign. That way you can fill them one after another until the intellisense does not pop up any more.

Visual Studio should have autocomplete when you use variable initialasition that way.

when you place the comma, hit enter and it will list the remaining properties.

If you use CTRL + SPACE it will give a list of ALL properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM