Las palabras clave son las palabras en un idioma que se utilizan para algún proceso interno o representan algunas acciones predefinidas. short es una palabra clave que se usa para declarar una variable que puede almacenar un valor entero con signo del rango -32, 768 a 32, 767 . Es un alias de System.Int16 .
Sintaxis:
short variable_name = value;
La palabra clave corta ocupa 2 bytes (16 bits) de espacio en la memoria.
Ejemplo:
Input: num: 2 Output: num: 2 Size of a short variable: 2 Input: num = 20200 Output: num: 20200 Type of num: System.Int16 Size of a short variable: 2
Ejemplo 1:
// C# program for short keyword using System; using System.Text; class Prog { static void Main(string[] args) { // variable declaration short num = 2; // to print value Console.WriteLine("num: " + num); // to print size Console.WriteLine("Size of a short variable: " + sizeof(short)); } }
Producción:
num: 2 Size of a short variable: 2
Ejemplo 2:
// C# program for short keyword using System; using System.Text; namespace Test { class Prog { static void Main(string[] args) { // variable declaration short num = 20200; // to print value Console.WriteLine("num: " + num); // to print type of variable Console.WriteLine("Type of num: " + num.GetType()); // to print size Console.WriteLine("Size of a short variable: " + sizeof(short)); // to print 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(); } } }
Producción:
num: 20200 Type of num: System.Int16 Size of a short variable: 2 Min value of short: -32768 Max value of short: 32767
Publicación traducida automáticamente
Artículo escrito por shivanisinghss2110 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA