using
System;
class
GFG {
public
static
void
Main()
{
try
{
byte
[] byte1 = {2, 4, 6, 8, 10, 12,
14, 16, 18, 20};
byte
[] byte2 = {10, 20, 30, 40, 50};
get
(byte1, "byte1");
Console.WriteLine("length of inArray
is
negative");
char
[] base64CharArray =
new
char
[10];
int
val = Convert.ToBase64CharArray(byte2, 0,
-10, base64CharArray, 0);
Console.WriteLine("Converted
byte
value: {0}", val);
}
catch
(ArgumentNullException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
catch
(ArgumentOutOfRangeException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(),
e.Message);
}
}
public
static
void
get
(
byte
[] bytes,
string
str)
{
Console.WriteLine("For {0}", str);
long
arrayLength = (
long
)((4.0d / 3.0d) * bytes.Length);
if
(arrayLength % 4 != 0)
arrayLength += 4 - arrayLength % 4;
char
[] base64CharArray =
new
char
[arrayLength];
int
val = Convert.ToBase64CharArray(bytes, 0,
bytes.Length, base64CharArray, 0);
Console.WriteLine("Total no of bytes: {0}", val);
Console.Write("base64CharArray: ");
for
(
int
j = 0; j < base64CharArray.Length; j++)
Console.Write("{0}", base64CharArray[j]);
Console.WriteLine("\n");
}
}