using
System;
using
System.Globalization;
class
GFG {
public
static
void
Main()
{
try
{
CultureInfo cultures =
new
CultureInfo(
"en-US"
);
string
[] values = {
"12345"
,
"+3456"
,
"3456"
};
Console.Write(
"Converted ushort value"
+
" of specified strings: "
);
for
(
int
j = 0; j < values.Length; j++)
{
get
(values[j], cultures);
}
Console.WriteLine(
"\n"
);
string
s =
"123 456, 789"
;
Console.WriteLine(
"format of s is invalid "
);
ushort
val = Convert.ToUInt16(s, cultures);
Console.Write(
" {0}, "
, val);
}
catch
(FormatException e)
{
Console.Write(
"Exception Thrown: "
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
catch
(OverflowException e)
{
Console.Write(
"Exception Thrown: "
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
}
public
static
void
get
(
string
s,
CultureInfo cultures)
{
ushort
val = Convert.ToUInt16(s, cultures);
Console.Write(
" {0}, "
, val);
}
}