
- 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
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
- Related Articles
- Int16.CompareTo() Method in C#
- C# Enum ToString() Method
- Int16.Equals Method in C# with Examples
- Int16.GetHashCode() Method in C# with Examples
- Int16.GetTypeCode Method in C# with Examples
- Int64.ToString() Method in C#
- Java toString() method.
- UInt32.ToString() Method in C# with Examples
- UInt16.ToString Method in C# with Examples
- UInt64.ToString() Method in C# with Examples
- C# Int16 Struct
- Java Signature toString() method
- JavaScript RegExp toString() Method
- ShortBuffer toString() method in Java
- Provider toString() method in Java

Advertisements