Keywords are the words in a language that are used for some internal process or represent some predefined actions. long is a keyword that is used to declare a variable which can store a signed integer value from the range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. It is an alias of System.Int64.
Syntax:
csharp
Output:
csharp
long variable_name = value;long keyword occupies 8 bytes (64 bits) space in the memory. Example:
Input: num: 34638
Output: num: 34638
Size of a long variable: 8
Input: num = -79349367648374345
Output: Type of num: System.Int64
num: -79349367648374345
Size of a long variable: 8
If we input number beyond the range, it shows error- Integral constant is too largeExample 1:
// C# program for long keyword
using System;
using System.Text;
class GFG {
static void Main(string[] args)
{
// variable declaration
long num = 34638;
// to print value
Console.WriteLine("num: " + num);
// to print size
Console.WriteLine("Size of a long variable: " + sizeof(long));
}
}
num: 34638 Size of a long variable: 8Example 2:
// C# program for long keyword
using System;
using System.Text;
namespace Test {
class GFG {
static void Main(string[] args)
{
// variable declaration
long num = -79349367648374345;
// to print type of variable
Console.WriteLine("Type of num: " + num.GetType());
// to print value
Console.WriteLine("num: " + num);
// to print size
Console.WriteLine("Size of a long variable: " + sizeof(long));
// to print minimum & maximum value of long
Console.WriteLine("Min value of long: " + long.MinValue);
Console.WriteLine("Max value of long: " + long.MaxValue);
// hit ENTER to exit
Console.ReadLine();
}
}
}
Output:
Type of num: System.Int64 num: -79349367648374345 Size of a long variable: 8 Min value of long: -9223372036854775808 Max value of long: 9223372036854775807