long keyword in C#

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

num: 34638
Size of a long variable: 8

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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();
    }
}
}

chevron_right


Output:

Type of num: System.Int64
num: -79349367648374345
Size of a long variable: 8
Min value of long: -9223372036854775808
Max value of long: 9223372036854775807



My Personal Notes arrow_drop_up


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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.