Export (0) Print
Expand All

Convert.ToByte Method (String, Int32)

Converts the String representation of a number in a specified base to an equivalent 8-bit unsigned integer.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static byte ToByte (
	string value,
	int fromBase
)
public static byte ToByte (
	String value, 
	int fromBase
)
public static function ToByte (
	value : String, 
	fromBase : int
) : byte

Parameters

value

A String containing a number.

fromBase

The base of the number in value, which must be 2, 8, 10, or 16.

Return Value

An 8-bit unsigned integer equivalent to the number in value. -or- Zero if value is a null reference (Nothing in Visual Basic).

Exception typeCondition

ArgumentException

fromBase is not 2, 8, 10, or 16.

-or-

value, which represents a non-base 10 unsigned number, is prefixed with a negative sign.

FormatException

value contains a character that is not a valid digit in the base specified by fromBase. The exception message indicates there are no digits to convert if the first character in value is invalid; otherwise, the message indicates value contains invalid trailing characters.

OverflowException

value, which represents a base 10 unsigned number, is prefixed with a negative sign.

-or-

The return value is less than Byte.MinValue or larger than Byte.MaxValue.

If fromBase is 16, you can prefix the number specified by the value parameter with "0x" or "0X".

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft