I have a property
public int active { get; set; }
That in my db has a default value of 1. I would like to have this property default to 1 if not otherwise specified
public partial class test
{
public int Id { get; set; }
public string test1 { get; set; }
public int active { get; set; }
}
I saw that in c# 6 you can do
public int active { get; set; } = 1
But I am not using c# 6 :(. Thanks for the advice. (Very, very new to c# / OOP)
Just set it in the constructor:
public partial class Test
{
public int Id { get; set; }
public string Test1 { get; set; }
public int Active { get; set; }
public Test()
{
Active = 1;
}
}
I think that's simpler than avoiding the automatically-implemented property just for the sake of defaulting...
See more on this question at Stackoverflow