我有二个类:
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;该如何实现
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;该如何实现
{
public static Consts Checked = new Consts('','');
public static Consts UnChecked = new Consts('','');
}
那你在这里加一个string转换的函数
要么你直接去拿它的.code.
要么把这个.toString()给加上。
public static implicit operator string(Consts value)
{
return value.Code;
}