SByte SByte SByte SByte Struct

定义

重要

此 API 不符合 CLS。

符合 CLS 的替代方案
System.Int16

表示 8 位有符号整数。Represents an 8-bit signed integer.

public value class SByte : IComparable, IComparable<System::SByte>, IConvertible, IEquatable<System::SByte>, IFormattable
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct SByte : IComparable, IComparable<sbyte>, IConvertible, IEquatable<sbyte>, IFormattable
type sbyte = struct
    interface IFormattable
    interface IConvertible
Public Structure SByte
Implements IComparable, IComparable(Of SByte), IConvertible, IEquatable(Of SByte), IFormattable
继承
属性
实现

注解

SByte值类型表示其值介于-128 到 + 127 之间的整数。The SByte value type represents integers with values ranging from negative 128 to positive 127.

重要

SByte类型不符合 CLS 規格。The SByte type is not CLS-compliant. 符合 cls 的替代类型是Int16The CLS-compliant alternative type is Int16. Byte 可以改为使用替换正SByte值,范围为从零到MaxValueByte can be used instead to replace a positive SByte value that ranges from zero to MaxValue. 有关 CLS 遵从性的详细信息,请参阅语言独立性和与语言无关的组件For more information about CLS compliance, see Language Independence and Language-Independent Components.

SByte 提供用于比较此类型的实例,实例的值转换为其字符串表示形式,并将数字的字符串表示形式转换为此类型的实例方法。SByte provides methods to compare instances of this type, convert the value of an instance to its string representation, and convert the string representation of a number to an instance of this type.

格式规范代码如何控制值类型的字符串表示形式的信息,请参阅格式设置类型For information about how format specification codes control the string representation of value types, see Formatting Types.

字段

MaxValue MaxValue MaxValue MaxValue

表示 SByte 的最大可能值。Represents the largest possible value of SByte. 此字段为常数。This field is constant.

MinValue MinValue MinValue MinValue

表示 SByte 的最小可能值。Represents the smallest possible value of SByte. 此字段为常数。This field is constant.

方法

CompareTo(Object) CompareTo(Object) CompareTo(Object) CompareTo(Object)

将此实例与指定对象进行比较并返回一个对二者的相对值的指示。Compares this instance to a specified object and returns an indication of their relative values.

CompareTo(SByte) CompareTo(SByte) CompareTo(SByte) CompareTo(SByte)

将此实例与指定的 8 位有符号整数进行比较并返回对其相对值的指示。Compares this instance to a specified 8-bit signed integer and returns an indication of their relative values.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例是否等于指定的对象。Returns a value indicating whether this instance is equal to a specified object.

Equals(SByte) Equals(SByte) Equals(SByte) Equals(SByte)

返回一个值,该值指示此实例是否等于指定的 SByte 值。Returns a value indicating whether this instance is equal to a specified SByte value.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

GetTypeCode() GetTypeCode() GetTypeCode() GetTypeCode()

返回值类型 TypeCodeSByteReturns the TypeCode for value type SByte.

Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的字符串表示形式转换为它的等效 8 位有符号数值。Converts the string representation of a number that is in a specified style and culture-specific format to its 8-bit signed equivalent.

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

将指定样式的数字的字符串表示形式转换为它的等效 8 位有符号整数。Converts the string representation of a number in a specified style to its 8-bit signed integer equivalent.

Parse(String) Parse(String) Parse(String) Parse(String)

将数字的字符串表示形式转换为它的等效 8 位有符号整数。Converts the string representation of a number to its 8-bit signed integer equivalent.

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

将指定的区域性特定格式的数字的字符串表示形式转换为它的等效 8 位有符号整数。Converts the string representation of a number in a specified culture-specific format to its 8-bit signed integer equivalent.

ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider)

使用指定的区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider)

使用指定的格式和区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

ToString(String) ToString(String) ToString(String) ToString(String)

使用指定的格式,将此实例的数值转换为它的等效字符串表示形式。Converts the numeric value of this instance to its equivalent string representation, using the specified format.

ToString() ToString() ToString() ToString()

将此实例的数值转换为其等效的字符串表示形式。Converts the numeric value of this instance to its equivalent string representation.

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

尝试将数字的字符串表示形式转换为它的等效 SByte,并返回一个指示转换是否成功的值。Tries to convert the string representation of a number to its SByte equivalent, and returns a value that indicates whether the conversion succeeded.

TryParse(ReadOnlySpan<Char>, SByte) TryParse(ReadOnlySpan<Char>, SByte) TryParse(ReadOnlySpan<Char>, SByte) TryParse(ReadOnlySpan<Char>, SByte)
TryParse(String, NumberStyles, IFormatProvider, SByte) TryParse(String, NumberStyles, IFormatProvider, SByte) TryParse(String, NumberStyles, IFormatProvider, SByte) TryParse(String, NumberStyles, IFormatProvider, SByte)

尝试将指定样式和区域性特定格式的数字的字符串表示形式转换为其 SByte 等效项,并返回一个指示转换是否成功的值。Tries to convert the string representation of a number in a specified style and culture-specific format to its SByte equivalent, and returns a value that indicates whether the conversion succeeded.

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, SByte) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, SByte) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, SByte) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, SByte)

显式界面实现

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

有关此成员的说明,请参见 ToBoolean(IFormatProvider)For a description of this member, see ToBoolean(IFormatProvider).

IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider)

有关此成员的说明,请参见 ToByte(IFormatProvider)For a description of this member, see ToByte(IFormatProvider).

IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider)

有关此成员的说明,请参见 ToChar(IFormatProvider)For a description of this member, see ToChar(IFormatProvider).

IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider)

不支持此转换。This conversion is not supported. 尝试这样做会引发 InvalidCastExceptionAttempting to do so throws an InvalidCastException.

IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider)

有关此成员的说明,请参见 ToDecimal(IFormatProvider)For a description of this member, see ToDecimal(IFormatProvider).

IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider)

有关此成员的说明,请参见 ToDouble(IFormatProvider)For a description of this member, see ToDouble(IFormatProvider).

IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider)

有关此成员的说明,请参见 ToInt16(IFormatProvider)For a description of this member, see ToInt16(IFormatProvider).

IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider)

有关此成员的说明,请参见 ToInt32(IFormatProvider)For a description of this member, see ToInt32(IFormatProvider).

IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider)

有关此成员的说明,请参见 ToInt64(IFormatProvider)For a description of this member, see ToInt64(IFormatProvider).

IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider)

有关此成员的说明,请参见 ToSByte(IFormatProvider)For a description of this member, see ToSByte(IFormatProvider).

IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider)

有关此成员的说明,请参见 ToSingle(IFormatProvider)For a description of this member, see ToSingle(IFormatProvider).

IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider)

有关此成员的说明,请参见 ToType(Type, IFormatProvider)For a description of this member, see ToType(Type, IFormatProvider).

IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider)

有关此成员的说明,请参见 ToUInt16(IFormatProvider)For a description of this member, see ToUInt16(IFormatProvider).

IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider)

有关此成员的说明,请参见 ToUInt32(IFormatProvider)For a description of this member, see ToUInt32(IFormatProvider).

IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(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.

另请参阅