1

I have a class that has around 30 string properties in .Net 4.0. I need all of them to be initialized as Empty String. Currently I am writing this logic in constructor. Is there any better way for doing this with lesser number of lines of code?

REFERENCES

  1. msdn - DefaultValueAttribute Class

CODE

public class MakeHoldDetail
{
    public string Supplier { get; set; }
    public string Loc { get; set; }

    //constructor
    public MakeHoldDetail()
    {
        Supplier = String.Empty;
        Loc = String.Empty;
    }
}
LCJ
  • 22,196
  • 67
  • 260
  • 418
  • 3
    You're trying to initialize auto-properties as String.Empty, which there exists no shortcut syntax for. How are the questions any different other than the value you're trying to initialize them with (which is irrelevant)? – BoltClock Jun 08 '14 at 03:23
  • 1
    @Lijo Read this: [Best Practice: Initialize class fields in constructor or at declaration?](http://stackoverflow.com/questions/24551/best-practice-initialize-class-fields-in-constructor-or-at-declaration) – super Jun 08 '14 at 03:26

0 Answers0