就像是
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 ...