using
System;
class
GFG {
public
static
void
Main()
{
try
{
byte
[] bytes = { 32, 0, 0, 42, 0, 65, 0, 125, 0,
197, 0, 168, 3, 41, 4, 125 };
Console.Write(
"Initial Array: "
);
PrintIndexAndValues(bytes);
for
(
int
index = 0; index < bytes.Length + 1;
index = index + 2) {
if
(index == bytes.Length) {
Console.WriteLine();
Console.WriteLine(
"startIndex is greater than "
+
"the length of value minus 1."
);
char
values = BitConverter.ToChar(bytes, index);
}
else
{
char
values = BitConverter.ToChar(bytes, index);
Console.WriteLine(
"index element char"
);
Console.WriteLine(
" {0} {1} {2}"
,
index, bytes[index], values);
}
}
}
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);
}
catch
(ArgumentException e) {
Console.Write(
"Exception Thrown: "
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
}
public
static
void
PrintIndexAndValues(
byte
[] myArr)
{
for
(
int
i = 0; i < myArr.Length; i++) {
Console.Write(
"{0} "
, myArr[i]);
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(
"initial Array in string: {0} "
,
BitConverter.ToString(myArr));
Console.WriteLine();
}
}