开发者

how to initialise a public property

开发者 https://www.devze.com 2023-02-01 14:49 出处:网络
now how to initialise a value for it. I know that i can initialise a property as private int _formId=1;

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

0

精彩评论

暂无评论...
验证码 换一张
取 消