// C# program to demonstrate the
// Convert.FromBase64String(String) Method
using System;
class GFG {
// Main Method
public static void Main()
{
try {
// defining and initializing
// byte1 and byte2
byte[] byte1 = {2, 4, 6, 8, 10,
12, 14, 16, 18, 20};
byte[] byte2 = {10, 20, 30,
40, 50};
// calling get() Method
get(byte1, "byte1");
Console.WriteLine("");
get(byte2, "byte2");
}
catch (ArgumentNullException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
catch (FormatException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(),
e.Message);
}
}
// Defining get() method
public static void get(byte[] bytes, string str)
{
Console.WriteLine("For {0}", str);
// converting byte to base 64 string
string s = Convert.ToBase64String(bytes);
Console.WriteLine("The base 64 string: '{0}'", s);
Console.WriteLine("The base 64 string: '{0}'", s);
// converting base 64 string to byte array
byte[] val = Convert.FromBase64String(s);
Console.WriteLine("Converted byte value: {0}",
BitConverter.ToString(val));
}
}