Say I have an auto-implemented property
public int SheetNum { get; set; }
Is there anyway to set the default value of SheetNum
to 1, so it would be like
private int sheetNum = 1;
public int SheetNum
{
set { this.sheetNum = value; }
get { return this.sheetNum; }
}
You're almost there; you just have to initialize the value in the constructor:
public class MyClass
{
public MyClass()
{
Foo = 1;
}
public int Foo { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With