我有二个类:
public class CheckStatus
{
   public static Consts Checked = new Consts('','');
   public static Consts UnChecked = new Consts('','');
}public class Consts
{
    public string Text {}
    public string Code {}    public Consts(string argText,stringCode){}    public override string ToString()
        {
            return m_Code;
        }}平时用的时候是Label.Text = CheckStatus.UnCheck.Code;
我想实现的效果是Label.Text = CheckStatus.UnCheck;该如何实现

解决方案 »

  1.   

    public class CheckStatus
    {
      public static Consts Checked = new Consts('','');
      public static Consts UnChecked = new Consts('','');

    那你在这里加一个string转换的函数
      

  2.   

    好像不可以。
    要么你直接去拿它的.code.
    要么把这个.toString()给加上。
      

  3.   

    不过你可以这样,你把它的类型给改变一下,在你给它们赋值的时候,使用new Consts('','').code or new Consts('','').ToString().
      

  4.   

    new Consts('','').ToString() 肯定不行的..还要用.Text呢
      

  5.   

    在Consts类里面加入:
    public static implicit operator string(Consts value)
    {
        return value.Code;
    }