how to initialise a public property
now how to initialise a value for it. I know that i can initialise a property as
private int _formId=1;
public int FromID
{
get
{
return _formId;
}
set
{
_formId= value;
}
But if i create a property as
public int FromID { get; set; }开发者_如何学运维
How can i initialise its value
You could initialize it in the constructor of your class:
public class Foo
{
public Foo()
{
FromID = 1;
}
public int FromID { get; set; }
}
public int FromID { get; set; }
is a short hand for the first piece of code. If you need to set a value use the first piece of code
精彩评论