将类字符串设置为空

时间:2019-03-02 08:26:23

标签: c# database

这是类,字符串是数据库列,当我要调出列时如何将其设置为空?是字符串strDockey = string.Empty; ??

  public class SL_CS
        {
            public string strDocKey { get; set; }
            public string strDocNo { get; set; }
            public string strDOCDATE { get; set; }
            public string strPOSTDATE { get; set; }
            public string strTAXDATE { get; set;}
}

1 个答案:

答案 0 :(得分:0)

在类的构造函数中初始化属性:

public class SL_CS{

    // constructor gets called when you new this class
    public SL_CS{ 
        // set any properties as you would do normally 
        sl_cs.strDocKey = String.Empty; 
    }

    public string strDocKey { get; set; }
    public string strDocNo { get; set; }
    public string strDOCDATE { get; set; }
    public string strPOSTDATE { get; set; }
    public string strTAXDATE { get; set;}
}

现在上课时:

var inst = new SL_CS();

,然后检查inst.strDocKey,它将为String.Empty。您的其他属性将为空。