Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Int16.ToString() Method
The Int16.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 format parameter is a numeric format string.
Example
Let us now see an example −
using System;
public class Demo {
public static void Main() {
short val1 = 10;
short val2 = 10;
Console.WriteLine("Value1 = "+val1.ToString());
Console.WriteLine("Value2 = "+val2.ToString());
Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());
Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());
Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
}
}
Output
This will produce the following output −
Value1 = 10 Value2 = 10 HashCode for value1 = 655370 HashCode for value2 = 655370 Are they equal? = True
Example
Let us now see another example −
using System;
public class Demo {
public static void Main() {
short val1 = 20;
short val2 = 18;
Console.WriteLine("Value 1 = "+val1.ToString("F1"));
Console.WriteLine("Value 2 = "+val2.ToString("000000.0000"));
Console.WriteLine("Return value (comparison) = "+val1.CompareTo(val2));
}
}
Output
This will produce the following output −
Value 1 = 20.0 Value 2 = 000018.0000 Return value (comparison) = 2
Advertisements