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) long b = 99;
float c = 99.0F;
//b = c; //Error : Cannot implicitly convert type 'float' to 'long'.
c = b; // Running Successfully. Why?
Run Code Online (Sandbox Code Playgroud)
为什么数据类型的大小和隐式转换没有问题?我们知道
的大小float和long不同之处在下面给出...
Console.WriteLine("Long : " + sizeof(long)); // Output --> Long : 8
Console.WriteLine("Float : " + sizeof(float));// Output --> Float: 4
Run Code Online (Sandbox Code Playgroud) 假设我们有两个类Car和Driver,
我们可以制作像这样的对象
Car c=new Driver();
Run Code Online (Sandbox Code Playgroud)
并且能够调用汽车类的成员而不是驱动程序类的成员为什么和什么时候??