猿问

整数求和蓝调,短+=短问题

整数求和蓝调,短+=短问题

C#中的程序:


short a, b;

a = 10;

b = 10;

a = a + b; // Error : Cannot implicitly convert type 'int' to 'short'.


// we can also write this code by using Arithmetic Assignment Operator as given below


a += b; // But this is running successfully, why?


Console.Write(a);


眼眸繁星
浏览 351回答 3
3回答

慕慕森

嗯,+=接线员说你会增加a短暂的,短暂的=说你会覆写值,并具有操作的结果。手术a + b生成一个int,不知道它可以做其他操作,所以您试图将该int分配给空。
随时随地看视频慕课网APP
我要回答