
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Int64.ToString() Method in C#
The Int64.ToString() method in C# is used to convert the numeric value of this instance to its equivalent string representation.
Syntax
The syntax is as follows −
public override string ToString (); public string ToString (string format);
Above, the parameter format is a numeric format string.
Example
Let us now see an example −
using System; public class Demo { public static void Main(){ long val1 = 0; long val2 = Int64.MaxValue; Console.WriteLine("Value1 = "+val1.ToString()); Console.WriteLine("Value2 = "+val2.ToString()); Console.WriteLine("Are they equal? = "+val1.Equals(val2)); Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode()); Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode()); TypeCode type1 = val1.GetTypeCode(); TypeCode type2 = val2.GetTypeCode(); Console.WriteLine("TypeCode for val1 = "+val1.GetTypeCode()); Console.WriteLine("TypeCode for val2 = = "+val1.GetTypeCode()); } }
Output
This will produce the following output −
Value1 = 0 Value2 = 9223372036854775807 Are they equal? = False Value1 (HashCode) = 0 Value2 (HashCode) = -2147483648 TypeCode for val1 = Int64 TypeCode for val2 = = Int64
Example
Let us now see another example −
using System; public class Demo { public static void Main(){ long val1 = 87987687; long val2 = 35436367; Console.WriteLine("Value1 = "+val1.ToString("D8")); Console.WriteLine("Value2 = "+val2.ToString("X")); Console.WriteLine("Are they equal? = "+val1.Equals(val2)); Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode()); Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode()); TypeCode type1 = val1.GetTypeCode(); TypeCode type2 = val2.GetTypeCode(); Console.WriteLine("TypeCode for val1 = "+val1.GetTypeCode()); Console.WriteLine("TypeCode for val2 = = "+val1.GetTypeCode()); } }
Output
This will produce the following output −
Value1 = 87987687 Value2 = 21CB74F Are they equal? = False Value1 (HashCode) = 87987687 Value2 (HashCode) = 35436367 TypeCode for val1 = Int64 TypeCode for val2 = = Int64
- Related Articles
- C# Enum ToString() Method
- C# Int16.ToString() Method
- Int64.CompareTo Method in C# with Examples
- Int64.Equals Method in C# with Examples
- Int64.GetHashCode Method in C# with Examples
- Int64.GetTypeCode Method in C# with Examples
- UInt32.ToString() Method in C# with Examples
- UInt16.ToString Method in C# with Examples
- UInt64.ToString() Method in C# with Examples
- Java toString() method.
- ShortBuffer toString() method in Java
- Provider toString() method in Java
- Duration toString() method in Java
- MonthDay toString() Method in Java
- Instant toString() method in Java

Advertisements