看看下面的代碼:
sbyte sba, sbb,sbv;
sba = 1;
sbb = 2;
sbv = sba + sbb;
byte ba, bb, bv;
ba = 1;
bb = 2;
bv = ba + bb;
short sa, sb, sv;
sa = 1;
sb = 2;
sv = sa + sb;
ushort usa, usb, usv;
usa = 1;
usb = 2;
usv = usa + usb;
MessageBox.Show(string.Format("{0},{1},{2},{3}", sbv, bv, sv, usv));
你覺得這段代碼能否正確執行?結果會怎樣?
用VS2005打開項目測試一下你就會發現,這段代碼會出現編譯錯誤.
正確的代碼應該如下:
sbyte sba, sbb,sbv;
sba = 1;
sbb = 2;
sbv = (sbyte)(sba + sbb);
byte ba, bb,