System.Int16 Structure

public struct Int16 : IComparable, IFormattable

Base Types

Object
  ValueType
    Int16

This type implements IComparable and IFormattable.

Assembly

mscorlib

Library

BCL

Summary

Represents a 16-bit signed integer.

Description

The Int16 data type represents integer values ranging from negative 32,768 to positive 32,767; that is, hexadecimal: 0x8000 to 0x7FFF.

See Also

System Namespace

Members

Int16 Methods

Int16.CompareTo Method
Int16.Equals Method
Int16.GetHashCode Method
Int16.Parse(System.String) Method
Int16.Parse(System.String, System.Globalization.NumberStyles) Method
Int16.Parse(System.String, System.IFormatProvider) Method
Int16.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method
Int16.ToString(System.IFormatProvider) Method
Int16.ToString(System.String, System.IFormatProvider) Method
Int16.ToString() Method
Int16.ToString(System.String) Method

Int16 Fields

Int16.MaxValue Field
Int16.MinValue Field


Int16.CompareTo Method

public int CompareTo(object value);

Summary

Returns the sort order of the current instance compared to the specified Object.

Parameters

value
The Object to compare to the current instance.

Return Value

A Int32 containing a value that reflects the sort order of the current instance as compared to value. The following table defines the conditions under which the return value is a negative number, zero, or a positive number.

Return ValueDescription
Any negative numberCurrent instance < value.
ZeroCurrent instance == value.
Any positive numberCurrent instance > value, or value is a null reference.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is not a Int16 and is not a null reference.

Description

[Note: This method is implemented to support the IComparable interface.]

See Also

System.Int16 Structure, System Namespace

Int16.Equals Method

public override bool Equals(object obj);

Summary

Determines whether the current instance and the specified Object represent the same type and value.

Parameters

obj
The Object to compare to the current instance.

Return Value

true if obj represents the same type and value as the current instance. If obj is a null reference or is not an instance of Int16, returns false .

Description

[Note: This method overrides System.Object.Equals(System.Object).]

See Also

System.Int16 Structure, System Namespace

Int16.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for the current instance.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode.]

See Also

System.Int16 Structure, System Namespace

Int16.Parse(System.String) Method

public static short Parse(string s);

Summary

Returns the specified String converted to a Int16 value.

Parameters

s
A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.

Return Value

The Int16 value obtained from s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than System.Int16.MaxValue or less than System.Int16.MinValue.

Description

This version of System.Int16.Parse(System.String) is equivalent to System.Int16.Parse(System.String) (s, System.Globalization.NumberStyles.Integer, null ).

The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo.]

Example

This example demonstrates parsing a string to a Int16.

using System;
public class Int16ParseClass {
  public static void Main() {
    string str = "  100   ";
    Console.WriteLine("String: \"{0}\" <Int16> {1}",str,Int16.Parse(str));
  }
}
The output is

String: " 100 " <Int16> 100

See Also

System.Int16 Structure, System Namespace

Int16.Parse(System.String, System.Globalization.NumberStyles) Method

public static short Parse(string s, NumberStyles style);

Summary

Returns the specified String converted to a Int16 value.

Parameters

s
A String containing the value to convert. The string is interpreted using the style specified by style.
style
Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Integer style.

Return Value

The Int16 value obtained from s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than System.Int16.MaxValue or less than System.Int16.MinValue.

Description

This version of System.Int16.Parse(System.String) is equivalent to System.Int16.Parse(System.String)(s, style, null ).

The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo .]

See Also

System.Int16 Structure, System Namespace

Int16.Parse(System.String, System.IFormatProvider) Method

public static short Parse(string s, IFormatProvider provider);

Summary

Returns the specified String converted to a Int16value.

Parameters

s
A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.

Return Value

The Int16 value obtained from s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than System.Int16.MaxValue or less than System.Int16.MinValue.

Description

This version of System.Int16.Parse(System.String) is equivalent to System.Int16.Parse(System.String)(s, System.Globalization.NumberStyles.Integer, provider).

The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider is null or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

See Also

System.Int16 Structure, System Namespace

Int16.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method

public static short Parse(string s, NumberStyles style, IFormatProvider provider);

Summary

Returns the specified String converted to a Int16 value.

Parameters

s
A String containing the value to convert. The string is interpreted using the style specified by style.
style
Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Integer style.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.

Return Value

The Int16 value obtained from s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than System.Int16.MaxValue or less than System.Int16.MinValue.

Description

The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider is null or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

See Also

System.Int16 Structure, System Namespace

Int16.ToString(System.IFormatProvider) Method

public string ToString(IFormatProvider provider);

Summary

Returns a String representation of the value of the current instance.

Parameters

provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.

Return Value

A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the formatting information in the NumberFormatInfo instance supplied by provider.

Description

This version of System.Int16.ToString is equivalent to System.Int16.ToString("G", provider).

If provider is null or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

See Also

System.Int16 Structure, System Namespace

Int16.ToString(System.String, System.IFormatProvider) Method

public string ToString(string format, IFormatProvider provider);

Summary

Returns a String representation of the value of the current instance.

Parameters

format
A String containing a character that specifies the format of the returned string.
provider
A IFormatProvider that supplies a NumberFormatInfo instance containing culture-specific formatting information.

Return Value

A String representation of the current instance formatted as specified by format. The string takes into account the formatting information in the NumberFormatInfo instance supplied by provider.

Exceptions

Exception TypeCondition
FormatExceptionformat is invalid.

Description

If provider is null or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

If format is a null reference, the general format specifier "G" is used.

[Note: For a detailed description of formatting, see the IFormattable interface.

This method is implemented to support the IFormattable interface.

]

The following table lists the characters that are valid for the Int16 type.

Format CharactersDescription
"C", "c"Currency format.
"D", "d"Decimal format.
"E", "e"Exponential notation format.
"F", "f"Fixed-point format.
"G", "g"General format.
"N", "n"Number format.
"P", "p"Percent format.
"X", "x"Hexadecimal format.

See Also

System.Int16 Structure, System Namespace

Int16.ToString() Method

public override string ToString();

Summary

Returns a String representation of the value of the current instance.

Return Value

A String representation of the current instance formatted using the general format specifier ("G"). The string takes into account the current system culture.

Description

This version of System.Int16.ToString is equivalent to System.Int16.ToString(null , null ).

[Note: This method overrides System.Object.ToString.]

See Also

System.Int16 Structure, System Namespace

Int16.ToString(System.String) Method

public string ToString(string format);

Summary

Returns a String representation of the value of the current instance.

Parameters

format
A String that specifies the format of the returned string. [Note: For a list of valid values, see System.Int16.ToString(String, IFormatProvider).]

Return Value

A String representation of the current instance formatted as specified by format. The string takes into account the current system culture.

Exceptions

Exception TypeCondition
FormatExceptionformat is invalid.

Description

This version of System.Int16.ToString is equivalent to System.Int16.ToString(format, null).

If format is a null reference, the general format specifier "G" is used.

Example

This example demonstrates converting a Int16 to a string.

using System;
public class Int16ToStringExample {
   public static void Main() {
      Int16 i = 16;
      Console.WriteLine(i);
      string[] formats = {"c", "d", "e", "f", "g", "n", "p", "x" };
      foreach(string str in formats)
         Console.WriteLine("{0}: {1}", str, i.ToString(str));
   }
}
The output is

16

c: $16.00

d: 16

e: 1.600000e+001

f: 16.00

g: 16

n: 16.00

p: 1,600.00 %

x: 10

See Also

System.Int16 Structure, System Namespace

Int16.MaxValue Field

public const short MaxValue = 32767;

Summary

Contains the maximum value for the Int16 type.

Description

The value of this constant is 32,767 (hexadecimal 0X7FFF).

See Also

System.Int16 Structure, System Namespace

Int16.MinValue Field

public const short MinValue = -32768;

Summary

Contains the minimum value for the Int16 type.

Description

The value of this constant is -32,768 (hexadecimal 0X8000).

See Also

System.Int16 Structure, System Namespace