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,32};
Console.Write(
"Initial Array: "
);
PrintIndexAndValues(bytes);
Console.WriteLine(
"index element"
+
" ulong value"
);
for
(
int
index = 0; index < bytes.Length + 1;
index = index + 8) {
if
(index == bytes.Length) {
Console.WriteLine();
Console.WriteLine(
"startindex is {0} which is greater than "
+
"the length of Array minus 1."
, index);
ulong
values = BitConverter.ToUInt64(bytes, index);
Console.WriteLine(
" {0} {1} {2}"
, index,
BitConverter.ToString(bytes, index, 8), values);
}
else
{
ulong
values = BitConverter.ToUInt64(bytes, index);
Console.WriteLine(
" {0} {1} {2}"
, index,
BitConverter.ToString(bytes, index, 8), 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();
}
}