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 ...
有沒有C#3.5,我想你的意思是C#3下.NET 3.5 – Greg 2009-11-24 18:41:33
你覺得這是VB6? – ChaosPandion 2009-11-24 18:41:33
@Greg:我修復了主題行中的版本號:) – 2009-11-24 18:42:55