相关疑难解决方法(0)

整数蓝色,短+ +短问题

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);
Run Code Online (Sandbox Code Playgroud)

c# int types short

68
推荐指数
4
解决办法
1万
查看次数

char的+ = b运算符是否与a = a + b相同?

发现一个有趣的问题,以下代码运行时具有不同的结果:

char c = 'a';

c += 'a';   //passed
c = c + 'a'; //Cannot implicitly convert type 'int' to 'char'. An explicit conversion exists (are you missing a cast?)
Run Code Online (Sandbox Code Playgroud)

有什么区别a += ba=a+b,或只是编译器的代码检查错过呢?

我的观点是为什么char += charchar = (char+char)考虑时可以通过代码检查char = int

c#

37
推荐指数
2
解决办法
3494
查看次数

标签 统计

c# ×2

int ×1

short ×1

types ×1