System.SByte Structure

public struct SByte : IComparable, IFormattable, IComparable<SByte>, IEquatable<SByte>

Base Types

Object
  ValueType
    SByte

This type implements IComparable, IFormattable, System.IComparable<System.SByte>, and System.IEquatable<System.SByte>.

Assembly

mscorlib

Library

BCL

Summary

Represents an 8-bit signed integer.

Description

The SByte data type represents integer values ranging from negative 128 to positive 127; that is, hexadecimal 0x80 to 0x7F.

Attributes

CLSCompliantAttribute(false)

See Also

System Namespace

Members

SByte Methods

SByte.CompareTo(System.Object) Method
SByte.CompareTo(sbyte) Method
SByte.Equals(System.Object) Method
SByte.Equals(sbyte) Method
SByte.GetHashCode Method
SByte.Parse(System.String) Method
SByte.Parse(System.String, System.Globalization.NumberStyles) Method
SByte.Parse(System.String, System.IFormatProvider) Method
SByte.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method
SByte.ToString(System.IFormatProvider) Method
SByte.ToString(System.String, System.IFormatProvider) Method
SByte.ToString() Method
SByte.ToString(System.String) Method

SByte Fields

SByte.MaxValue Field
SByte.MinValue Field


SByte.CompareTo(System.Object) Method

public int CompareTo(object obj);

Summary

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

Parameters

obj
The Object to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to obj. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

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

Exceptions

Exception TypeCondition
ArgumentExceptionobj is not a SByte and is not a null reference.

Description

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

See Also

System.SByte Structure, System Namespace

SByte.CompareTo(sbyte) Method

public int CompareTo(sbyte value);

Summary

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

Parameters

value
The SByte to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

Return ValueDescription
A negative numberCurrent instance < value.
ZeroCurrent instance == value.
A positive numberCurrent instance > value.

Description

[Note: This method is implemented to support the System.IComparable<SByte> interface.]

See Also

System.SByte Structure, System Namespace

SByte.Equals(System.Object) 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 SByte, returns false .

Description

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

See Also

System.SByte Structure, System Namespace

SByte.Equals(sbyte) Method

public override bool Equals(sbyte obj);

Summary

Determines whether the current instance and the specified SByte represent the same value.

Parameters

obj
The SByte to compare to the current instance.

Return Value

true if obj represents the same value as the current instance; otherwise, false .

Description

[Note: This method is implemented to support the System.IEquatable<SByte> interface.]

See Also

System.SByte Structure, System Namespace

SByte.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.SByte Structure, System Namespace

SByte.Parse(System.String) Method

public static sbyte Parse(string s);

Summary

Returns the specified String converted to a SByte value.

Parameters

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

Return Value

The SByte value obtained from s.

Exceptions

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

Description

This version of System.SByte.Parse(System.String) is equivalent to System.SByte.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.]

This method is not CLS-compliant. For a CLS-compliant alternative use System.Int16.Parse(System.String) (String).

Example

This example demonstrates the System.SByte.Parse(System.String)(String) method.

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

String: " 100 " <SByte> 100

Attributes

CLSCompliantAttribute(false)

See Also

System.SByte Structure, System Namespace

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

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

Summary

Returns the specified String converted to a SByte 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 SByte 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.SByte.MaxValue or less than System.SByte.MinValue.

Description

This version of System.SByte.Parse(System.String) is equivalent to System.SByte.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.]

This method is not CLS-compliant. For a CLS-compliant alternative use System.Int16.Parse(System.String)(String, NumberStyles).

Attributes

CLSCompliantAttribute(false)

See Also

System.SByte Structure, System Namespace

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

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

Summary

Returns the specified String converted to a SByte value.

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 SByte 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.SByte.MaxValue or less than System.SByte.MinValue.

Description

This version of System.SByte.Parse(System.String) is equivalent to System.SByte.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.

This method is not CLS-compliant. For a CLS-compliant alternative use System.Int16.Parse(System.String) (String, IFormatProvider).

Attributes

CLSCompliantAttribute(false)

See Also

System.SByte Structure, System Namespace

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

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

Summary

Returns the specified String converted to a SByte 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 SByte 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.SByte.MaxValue or less than System.SByte.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.

This method is not CLS-compliant. For a CLS-compliant alternative use System.Int16.Parse(System.String)(String, NumberStyles, IFormatProvider).

Attributes

CLSCompliantAttribute(false)

See Also

System.SByte Structure, System Namespace

SByte.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.SByte.ToString is equivalent to System.SByte.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.SByte Structure, System Namespace

SByte.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 SByte 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.SByte Structure, System Namespace

SByte.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.SByte.ToString is equivalent to System.SByte.ToString (null , null ).

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

See Also

System.SByte Structure, System Namespace

SByte.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.SByte.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.SByte.ToString is equivalent to System.SByte.ToString (format, null ).

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

Example

This example demonstrates the System.SByte.ToString(String) method.

using System;
public class SByteToStringExample {
   public static void Main() {
      SByte i = 8;
      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

8

c: $8.00

d: 8

e: 8.000000e+000

f: 8.00

g: 8

n: 8.00

p: 800.00 %

x: 8

See Also

System.SByte Structure, System Namespace

SByte.MaxValue Field

public const sbyte MaxValue = 127;

Summary

Contains the maximum value for the SByte type.

Description

The value of this constant is 127 (hexadecimal 0X7F).

See Also

System.SByte Structure, System Namespace

SByte.MinValue Field

public const sbyte MinValue = -128;

Summary

Contains the minimum value for the SByte type.

Description

The value of this constant is -128 (hexadecimal 0X80).

See Also

System.SByte Structure, System Namespace