public struct Byte : IComparable, IFormattable
Object
ValueType
ByteThis type implements IComparable and IFormattable.
mscorlib
BCL
Represents an 8-bit unsigned integer.
The Byte data type represents integer values ranging from 0 to positive 255 (hexadecimal 0xFF).
System Namespace
Byte Methods
Byte.CompareTo Method
Byte.Equals Method
Byte.GetHashCode Method
Byte.Parse(System.String) Method
Byte.Parse(System.String, System.Globalization.NumberStyles) Method
Byte.Parse(System.String, System.IFormatProvider) Method
Byte.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method
Byte.ToString(System.IFormatProvider) Method
Byte.ToString(System.String, System.IFormatProvider) Method
Byte.ToString() Method
Byte.ToString(System.String) Method
Byte Fields
public int CompareTo(object value);
Returns the sort order of the current instance compared to the specified object.
- value
- The Object to compare to the current instance.
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 Value Description Any negative number Current instance < value. Zero Current instance == value. Any positive number Current instance > value, or value is a null reference.
Exception Type Condition ArgumentException value is not a Byte and is not a null reference.
[Note: This method is implemented to support the IComparable interface.]
System.Byte Structure, System Namespace
public override bool Equals(object obj);
Determines whether the current instance and the specified Object represent the same type and value.
- obj
- The Object to compare to the current instance.
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 Byte, returnsfalse
.
[Note: This method overrides System.Object.Equals(System.Object).]
System.Byte Structure, System Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 containing the hash code for the current instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode.]
System.Byte Structure, System Namespace
public static byte Parse(string s);
Returns the specified String converted to a Byte value.
- s
- A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.
The Byte value obtained from s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than System.Byte.MaxValue or less than System.Byte.MinValue.
This version of System.Byte.Parse(System.String) is equivalent to System.Byte.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.]
The following example demonstrates the System.Byte.Parse(System.String) method.
using System; public class ByteParseClass { public static void Main() { string str = " 100 "; Console.WriteLine("String: \"{0}\" <Byte> {1}",str,Byte.Parse(str)); } }The output is
String: " 100 " <Byte> 100
System.Byte Structure, System Namespace
public static byte Parse(string s, NumberStyles style);
Returns the specified String converted to a Byte value.
- 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.
The Byte value obtained from s .
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than System.Byte.MaxValue or less than System.Byte.MinValue.
This version of System.Byte.Parse(System.String) is equivalent to System.Byte.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 .]
System.Byte Structure, System Namespace
public static byte Parse(string s, IFormatProvider provider);
Returns the specified String converted to a Byte value.
- 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.
The Byte value obtained from s .
Exception Type Condition ArgumentNullException s is a null reference. OverflowException s represents a number greater than System.Byte.MaxValue or less than System.Byte.MinValue. FormatException s is not in the correct style.
This version of System.Byte.Parse(System.String) is equivalent to System.Byte.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.
System.Byte Structure, System Namespace
public static byte Parse(string s, NumberStyles style, IFormatProvider provider);
Returns the specified String converted to a Byte value.
- 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.
The Byte value obtained from s .
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than System.Byte.MaxValue or less than System.Byte.MinValue.
The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider isnull
or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.
System.Byte Structure, System Namespace
public string ToString(IFormatProvider provider);
Returns a String representation of the value of the current instance.
- provider
- A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.
A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the information in the NumberFormatInfo instance supplied by provider.
This version of System.Byte.ToString is equivalent to System.Byte.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.
System.Byte Structure, System Namespace
public string ToString(string format, IFormatProvider provider);
Returns a String representation of the value of the current instance.
- 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.
A String representation of the current instance formatted as specified by format. The string takes into account the information in the NumberFormatInfo instance supplied by provider.
Exception Type Condition FormatException format is invalid.
If provider isnull
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.The following table lists the characters that are valid for the Byte type:
[Note: For a detailed description of formatting, see the IFormattable interface.
Format Characters Description "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. This method is implemented to support the IFormattable interface.
]
System.Byte Structure, System Namespace
public override string ToString();
Returns a String representation of the value of the current instance.
A String representation of the current instance formatted using the general format specifier ("G"). The string takes into account the current system culture.
This version of System.Byte.ToString is equivalent to System.Byte.ToString (null
,null
).[Note: This method overrides System.Object.ToString .]
System.Byte Structure, System Namespace
public string ToString(string format);
Returns a String representation of the value of the current instance.
- format
- A String that specifies the format of the returned string. [Note: For a list of valid values, see System.Byte.ToString(String, IFormatProvider ).]
A String representation of the current instance formatted as specified by format. The string takes into account the current system culture.
Exception Type Condition FormatException format is invalid.
This version of System.Byte.ToString is equivalent to System.Byte.ToString (format ,null
).If format is
null
, the general format specifier "G" is used.
The following example demonstrates the System.Byte.ToString method.
using System; public class ByteToStringExample { public static void Main() { Byte b = 8; Console.WriteLine(b); String[] formats = {"c", "d", "e", "f", "g", "n", "p", "x" }; foreach(String str in formats) Console.WriteLine("{0}: {1}", str, b.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
System.Byte Structure, System Namespace
public const byte MaxValue = 255;
Contains the maximum value for the Byte type.
The value of this constant is 255 (hexadecimal 0XFF).
System.Byte Structure, System Namespace
public const byte MinValue = 0;
Contains the minimum value for the Byte type.
The value of this constant is 0.
System.Byte Structure, System Namespace