C# SByte Parse(String)

Description

SByte Parse(String) converts the string representation of a number to its 8-bit signed integer equivalent.

Syntax

SByte.Parse(String) has the following syntax.


[CLSCompliantAttribute(false)]
public static sbyte Parse(
  string s
)

Parameters

SByte.Parse(String) has the following parameters.

  • s - A string that represents a number to convert. The string is interpreted using the NumberStyles.Integer style.

Returns

SByte.Parse(String) method returns An 8-bit signed integer that is equivalent to the number contained in the s parameter.

Example

The following example demonstrates how to convert a string value into a signed byte value using the Parse method.


/*from www .ja va 2s. co m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    string[] values = { "-16", "  -3", "+ 12", " +12 ", "  12  ",
                        "+120", "(103)", "192", "-160" };
    
    // Parse each string and display the result. 
    foreach (string value in values)
    {
       try {
          Console.WriteLine("Converted '{0}' to the SByte value {1}.",
                            value, SByte.Parse(value));
       }
       catch (FormatException) {
          Console.WriteLine("'{0}' cannot be parsed successfully by SByte type.",
                            value);
       }                              
       catch (OverflowException) {
          Console.WriteLine("'{0}' is out of range of the SByte type.",
                            value);
       }                                                                        
    }

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version