long keyword in C#

Last Updated : 15 Jul, 2025
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: csharp
// 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: csharp
// 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
Comment
Article Tags:

Explore