Int16 結構

定義

表示 16 位元帶正負號的整數。Represents a 16-bit signed integer.

public value class Int16 : IComparable, IComparable<short>, IConvertible, IEquatable<short>, IFormattable
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Int16 : IComparable, IComparable<short>, IConvertible, IEquatable<short>, IFormattable
type int16 = struct
    interface IFormattable
    interface IConvertible
Public Structure Int16
Implements IComparable, IComparable(Of Short), IConvertible, IEquatable(Of Short), IFormattable
繼承
屬性
實作

備註

Int16值型別代表帶正負號的整數值,範圍從負32768到正32767。The Int16 value type represents signed integers with values ranging from negative 32768 through positive 32767.

此類型提供將此類型的實例值轉換成其字串表示的方法,將數位的字串表示轉換成這個類型的實例,並比較這個類型的實例。This type provides methods to convert the value of an instance of this type to its string representation, to convert the string representation of a number to an instance of this type, and to compare instances of this type.

您也可以呼叫Math類別的成員來執行廣泛的數值作業,包括取得數位的絕對值、從整數除法計算商和餘數,判斷兩個的最大或最小值整數、取得數位的正負號,以及進位數位。You can also call the members of the Math class to perform a wide range of numeric operations, including getting the absolute value of a number, calculating the quotient and remainder from integral division, determining the maximum or minimum value of two integers, getting the sign of a number, and rounding a number.

如需格式規格代碼如何控制數值型別的字串標記法的詳細資訊,請參閱格式化類型For information about how format specification codes control the string representation of value types, see Formatting Types.

欄位

MaxValue

代表 Int16 最大的可能值。Represents the largest possible value of an Int16. 這個欄位是常數。This field is constant.

MinValue

代表 Int16 最小的可能值。Represents the smallest possible value of Int16. 這個欄位是常數。This field is constant.

方法

CompareTo(Int16)

比較這個執行個體與指定的 16 位元帶正負號整數,並且傳回整數,這個整數表示這個執行個體的值小於、等於或大於所指定 16 位元帶正負號整數的值。Compares this instance to a specified 16-bit signed integer and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified 16-bit signed integer.

CompareTo(Object)

比較這個執行個體與指定的物件,並且傳回整數,這個整數表示這個執行個體的值小於、等於或大於物件的值。Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the object.

Equals(Int16)

傳回值,表示這個執行個體是否等於指定的 Int16 值。Returns a value indicating whether this instance is equal to a specified Int16 value.

Equals(Object)

傳回值,指出這個執行個體 (Instance) 是否和指定的物件相等。Returns a value indicating whether this instance is equal to a specified object.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetTypeCode()

傳回實值類型 TypeCodeInt16Returns the TypeCode for value type Int16.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
Parse(String)

將數字的字串表示轉換成它的對等 16 位元帶正負號的整數。Converts the string representation of a number to its 16-bit signed integer equivalent.

Parse(String, IFormatProvider)

將指定特定文化特性格式之數字的字串表示轉換成它的對等 16 位元帶正負號的整數。Converts the string representation of a number in a specified culture-specific format to its 16-bit signed integer equivalent.

Parse(String, NumberStyles)

將指定樣式之數字的字串表示轉換成它的對等 16 位元帶正負號的整數。Converts the string representation of a number in a specified style to its 16-bit signed integer equivalent.

Parse(String, NumberStyles, IFormatProvider)

將指定樣式和特定文化特性格式之數字的字串表示轉換成它的對等 16 位元帶正負號的整數。Converts the string representation of a number in a specified style and culture-specific format to its 16-bit signed integer equivalent.

ToString()

將這個執行個體的數值轉換為它的相等字串表示。Converts the numeric value of this instance to its equivalent string representation.

ToString(IFormatProvider)

使用指定的特定文化特性格式資訊,將這個執行個體的數值轉換成它的相等字串表示。Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

ToString(String)

使用指定格式,將這個執行個體的數值轉換成它的相等字串表示。Converts the numeric value of this instance to its equivalent string representation, using the specified format.

ToString(String, IFormatProvider)

使用指定的格式和文化特性特定的格式資訊,將這個執行個體的數值轉換成它的對等字串表示。Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific formatting information.

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
TryParse(ReadOnlySpan<Char>, Int16)
TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Int16)
TryParse(String, Int16)

將數字的字串表示轉換成它的對等 16 位元帶正負號的整數。Converts the string representation of a number to its 16-bit signed integer equivalent. 傳回值會指出轉換成功或失敗。A return value indicates whether the conversion succeeded or failed.

TryParse(String, NumberStyles, IFormatProvider, Int16)

將指定樣式和特定文化特性格式之數字的字串表示轉換成它的對等 16 位元帶正負號的整數。Converts the string representation of a number in a specified style and culture-specific format to its 16-bit signed integer equivalent. 傳回值會指出轉換成功或失敗。A return value indicates whether the conversion succeeded or failed.

明確介面實作

IComparable.CompareTo(Object)
IConvertible.GetTypeCode()
IConvertible.ToBoolean(IFormatProvider)

如需這個成員的說明,請參閱 ToBoolean(IFormatProvider)For a description of this member, see ToBoolean(IFormatProvider).

IConvertible.ToByte(IFormatProvider)

如需這個成員的說明,請參閱 ToByte(IFormatProvider)For a description of this member, see ToByte(IFormatProvider).

IConvertible.ToChar(IFormatProvider)

如需這個成員的說明,請參閱 ToChar(IFormatProvider)For a description of this member, see ToChar(IFormatProvider).

IConvertible.ToDateTime(IFormatProvider)

不支援這個轉換。This conversion is not supported. 嘗試使用這個方法會擲回 InvalidCastExceptionAttempting to use this method throws an InvalidCastException.

IConvertible.ToDecimal(IFormatProvider)

如需這個成員的說明,請參閱 ToDecimal(IFormatProvider)For a description of this member, see ToDecimal(IFormatProvider).

IConvertible.ToDouble(IFormatProvider)

如需這個成員的說明,請參閱 ToDouble(IFormatProvider)For a description of this member, see ToDouble(IFormatProvider).

IConvertible.ToInt16(IFormatProvider)

如需這個成員的說明,請參閱 ToInt16(IFormatProvider)For a description of this member, see ToInt16(IFormatProvider).

IConvertible.ToInt32(IFormatProvider)

如需這個成員的說明,請參閱 ToInt32(IFormatProvider)For a description of this member, see ToInt32(IFormatProvider).

IConvertible.ToInt64(IFormatProvider)

如需這個成員的說明,請參閱 ToInt64(IFormatProvider)For a description of this member, see ToInt64(IFormatProvider).

IConvertible.ToSByte(IFormatProvider)

如需這個成員的說明,請參閱 ToSByte(IFormatProvider)For a description of this member, see ToSByte(IFormatProvider).

IConvertible.ToSingle(IFormatProvider)

如需這個成員的說明,請參閱 ToSingle(IFormatProvider)For a description of this member, see ToSingle(IFormatProvider).

IConvertible.ToType(Type, IFormatProvider)

如需這個成員的說明,請參閱 ToType(Type, IFormatProvider)For a description of this member, see ToType(Type, IFormatProvider).

IConvertible.ToUInt16(IFormatProvider)

如需這個成員的說明,請參閱 ToUInt16(IFormatProvider)For a description of this member, see ToUInt16(IFormatProvider).

IConvertible.ToUInt32(IFormatProvider)

如需這個成員的說明,請參閱 ToUInt32(IFormatProvider)For a description of this member, see ToUInt32(IFormatProvider).

IConvertible.ToUInt64(IFormatProvider)

如需這個成員的說明,請參閱 ToUInt64(IFormatProvider)For a description of this member, see ToUInt64(IFormatProvider).

適用於

執行緒安全性

此類型的所有成員都是安全線程。All members of this type are thread safe. 出現在修改實例狀態的成員實際上會傳回以新值初始化的新實例。Members that appear to modify instance state actually return a new instance initialized with the new value. 如同任何其他類型,讀取和寫入包含此類型之實例的共用變數必須受到鎖定保護,以確保執行緒安全性。As with any other type, reading and writing to a shared variable that contains an instance of this type must be protected by a lock to guarantee thread safety.

另請參閱