Parse string to byte and catch the OverflowException and FormatException : byte « Data Types « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Data Types » byteScreenshots 
Parse string to byte and catch the OverflowException and FormatException
    

using System;

public class Example
{
   public static void Main()
   {
        
        string string1 = "244";
        try {
           byte byte1 = Byte.Parse(string1);
           Console.WriteLine(byte1);
        }
        catch (OverflowException) {
           Console.WriteLine("'{0}' is out of range of a byte.", string1);
        }
        catch (FormatException) {
           Console.WriteLine("'{0}' is out of range of a byte.", string1);
        }
    }
}

   
    
    
    
  
Related examples in the same category
1.An int, a short, and a float are included in a mathematical expression giving a float result.
2.Use byteUse byte
3.Format byte with X4
4.Read short from byte array
5.Write short value to byte array
6.Read Int 24 from byte array
7.Read int 32 from byte array
8.Write int 32 to byte array
9.Byte array Index Of
10.Convert int to byte
11.Convert double to byte
12.Using Convert.ToByte to convert value to byte
13.Parse hexadecimal number to byte decimal
14.byte default format and leading zeros format
15.Format byte value to its hexadecimal form
16.Convert byte value to its base 2(Binary), base 8(Octal) and base 16(Hex) forms
17.Byte value binary and operation
18.byte hexadecimal literal
19.Byte.MaxValue, Byte.MinValue
20.Parse string with a culture-specific format to byte with IFormatProvider
21.Parse byte value with trailing sign or leading sign
22.Converts Byte to string with the culture-specific formatting information.
23.byte value standard string format
24.Format a byte value to string with culture-specific formatting information.
25.Tries to parse string to Byte
26.Parse string to byte with number style setting
27.Convert Bytes To String
28.Count Non Zero Bytes
29.Get Unsigned Byte Value
30.Convert Byte to Short
31.Convert Byte to Integer
32.Get Compressed Int Size
33.Compress Int
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.