how to set all attributes of an object a value

Hi,

   In Visual Studio 2026, csharp, I want like this :

  Persion p =new Persion;

 Then auto generate all attributes assignment:

 p.name="";

p.age=0;

p.address="";

p.a="";

Thanks.

0
1 comment

Hi,
 
Thank you for reaching out to JetBrains support.

  1. Create the object using an empty object initializer:
    Persion p = new Persion { };
  2. Place the cursor inside the braces { | }
  3. Press Alt+Enter to access ReSharper’s actions menu
  4. Select “Initialize members”.

If you'd like to separate the object creation from its member initialization, you can:

  1. Select all the members inside { }.
  2. Press Alt+Enter.
  3. Select "Convert initializer to assignment."

I hope this helps. Please let me know if this solution doesn’t meet your goals. 

0

Please sign in to leave a comment.