c-sharp
  1. c-sharp-program-to-demonstrate-the-working-of-keyword-long

Program to Demonstrate the Working of Keyword long - (C# Basic Programs)

In C#, the keyword long is used to declare a variable of type int64 that can store values within the range of signed 64-bit integers. In this tutorial, we will discuss a program that demonstrates the working of the keyword long in C#.

Syntax

The syntax for declaring a long variable in C# is as follows:

long variableName;

Example

using System;

class Program {
    static void Main(string[] args) {
        long longNum = 1234567890123456789;
        Console.WriteLine("The value of the longNum variable is: {0}", longNum);
    }
}

Output:

The value of the longNum variable is: 1234567890123456789

Explanation

In the above program, we declare a long variable named longNum and assign it a value of 1234567890123456789. Since the value is within the range of int64, the program successfully compiles and executes without any issues.

If the value assigned to a long variable exceeds the range of int64, the program will throw an error.

Use

The long keyword in C# is useful when we need to use a large number that cannot be stored within the range of a standard int variable. It allows us to store and operate on large numbers without encountering any issues related to overflow or datatype limitations.

Summary

In this tutorial, we discussed a program that demonstrates the working of the long keyword in C#. We saw the syntax, example, explanation, and use of the long keyword in C#. By using the long keyword, programmers can work with large numbers without encountering datatype limitations or overflow issues.

Published on: