Tag: 含蓄

在c#3.0中,是否可以将隐式运算符添加到字符串类中?

就像是 public static class StringHelpers { public static char first(this string p1) { return p1[0]; } public static implicit operator Int32(this string s) //this doesn’t work { return Int32.Parse(s); } } 所以: string str = “123”; char oneLetter = str.first(); //oneLetter = ‘1’ int answer = str; // Cannot implicitly convert …