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)

返回一个值,该值指示此实例是否等于指定的对象。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.

另请参阅