Convert.ToByte Method (Object)
Silverlight
Converts the value of the specified Object to an 8-bit unsigned integer.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Object
An Object that implements the IConvertible interface or null.
Return Value
Type: System.ByteAn 8-bit unsigned integer equivalent to the value of value, or zero if value is null.
| Exception | Condition |
|---|---|
| InvalidCastException | value does not implement IConvertible. |
If value is not null, this method wraps a call to the IConvertible.ToByte implementation of the underlying type of value.
The following code sample illustrates the use of ToByte, converting a String value to a Byte :
public void ConvertStringByte(string stringVal) { byte byteVal = 0; try { byteVal = System.Convert.ToByte(stringVal); outputBlock.Text += String.Format("{0} as a byte is: {1}", stringVal, byteVal) + "\n"; } catch (System.OverflowException) { outputBlock.Text += String.Format( "Conversion from string to byte overflowed.") + "\n"; } catch (System.FormatException) { outputBlock.Text += String.Format( "The string is not formatted as a byte.") + "\n"; } catch (System.ArgumentNullException) { outputBlock.Text += String.Format( "The string is null.") + "\n"; } //The conversion from byte to string is always valid. stringVal = System.Convert.ToString(byteVal); outputBlock.Text += String.Format("{0} as a string is {1}", byteVal, stringVal) + "\n"; }
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.