c# short
C#短关键字 (C# short keyword)
In C#, short is a keyword which is used to declare a variable that can store a signed integer value between the range of -32,768 to 32,767. short keyword is an alias of System.Int16.
在C#中, short是一个关键字,用于声明一个变量,该变量可以存储介于-32,768到32,767之间的有符号整数值。 short关键字是System.Int16的别名。
It occupies 2 bytes (16 bits) space in the memory.
它在内存中占用2个字节(16位)的空间。
Syntax:
句法:
short variable_name = value;
C#代码演示短关键字示例 (C# code to demonstrate example of short keyword)
Here, we are declaring a short variable num, initializing it with the value 12345 and printing its value, type and size of a short type variable.
在这里,我们宣布一个短变量num,与价值12345初始化它和印刷短类型的变量它的价值,类型和大小。
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//variable declaration
short num = 12345;
//printing value
Console.WriteLine("num: " + num);
//printing type of variable
Console.WriteLine("Type of num: " + num.GetType());
//printing size
Console.WriteLine("Size of a short variable: " + sizeof(short));
//printing minimum & maximum value of short
Console.WriteLine("Min value of short: " + short.MinValue);
Console.WriteLine("Max value of short: " + short.MaxValue);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
num: 12345
Type of num: System.Int16
Size of a short variable: 2
Min value of short: -32768
Max value of short: 32767
翻译自: https://www.includehelp.com/dot-net/short-keyword-in-c-sharp.aspx
c# short