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:
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 large
Example 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)); } } |
Output:
num: 34638 Size of a long variable: 8
Example 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
Recommended Posts:
- How to implement is functionality without using is keyword in C#
- C# | this Keyword
- C# | finally keyword
- C# | as Operator Keyword
- C# | is Operator Keyword
- Is vs As operator keyword in C#
- Static keyword in C#
- typeof Operator Keyword in C#
- Invoking an overloaded constructor using this keyword in C#
- Difference between readonly and const keyword in C#
- LINQ | Let Keyword
- uint keyword in C#
- byte Keyword in C#
- decimal keyword in C#
- char keyword in C#
- bool Keyword in C#
- sbyte Keyword in C#
- float keyword in C#
- double Keyword in C#
- void Keyword in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

