将类字符串设置为空

问题描述 投票:-2回答:1

这是类,字符串是数据库列,当我想将其调出时,如何将列设置为空?是字符串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;}
}
c# database
1个回答
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。您的其他属性将为null。

© www.soinside.com 2019 - 2024. All rights reserved.