I have the following class:
public class Topic
{
public string Topic { get; set; }
public string Description { get; set; }
public int Count { get; set; }
}
I would like to have the Count always set to zero when the class is created with the following:
var abc = new Topic {
Topic = "test1",
Description = "description1"
}
I am a bit confused with constructor. Is this possible or do I need to specify Topic, Description and Count when I create abc?
You have a few different options.
1)
intdefaults to zero so it will be zero if you dont initialize it.2) you can use a constructor
3) You can use a backing field instead of auto-property and initialize that to zero