c# 问题,Char 怎么隐式转换 string ?
stringstr3=Convert.ToChar(0x44);stringstr4=Convert.ToChar(0x45);stringstr5=Convert.To...
string str3 = Convert.ToChar(0x44);
string str4 = Convert.ToChar(0x45);
string str5 = Convert.ToChar(0x4c);
string str6 = Convert.ToChar(0x54);
string str7 = Convert.ToChar(70);
string str8 = Convert.ToChar(0x52);
string str9 = Convert.ToChar(0x4f);
string str10 = Convert.ToChar(0x4d);
string str11 = Convert.ToChar(0x42);
string str12 = Convert.ToChar(0x5f); 展开
string str4 = Convert.ToChar(0x45);
string str5 = Convert.ToChar(0x4c);
string str6 = Convert.ToChar(0x54);
string str7 = Convert.ToChar(70);
string str8 = Convert.ToChar(0x52);
string str9 = Convert.ToChar(0x4f);
string str10 = Convert.ToChar(0x4d);
string str11 = Convert.ToChar(0x42);
string str12 = Convert.ToChar(0x5f); 展开
3个回答
展开全部
public class MyString
{
private string Value { get; set; }
public MyString(string value)
{
this.Value = value;
}
public MyString(char value)
{
this.Value = value.ToString();
}
// 以下为互相隐式转换
public static implicit operator MyString(char value)
{
return new MyString(value);
}
public static implicit operator char(MyString value)
{
return Convert.ToChar(value.Value);
}
public static implicit operator String(MyString value)
{
return value.Value.ToString();
}
public static implicit operator MyString(String value)
{
return new MyString(value);
}
}
class Program
{
static void Main(string[] args)
{
char ch = 'C';
MyString my = ch; // 隐式 char->MyString
string str = my; // 隐式 MyString->String
Console.WriteLine(str.ToString());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询