c# - "FormatException" not thrown when ToInt32() method has invalid argument type -
1)
class program { static void main(string[] args) { int a; = convert.toint32( "a" ); console.write(a); } }
i formatexception
message: input string not in correct format
. , quite understood.
2)
class program { static void main(string[] args) { int a; = convert.toint32( console.read() ); console.write(a); } }
in second case, can type characters, example abc
, displayed in console.
question: why doesn't throw formatexception
in second case , why works non int
characters?
update
with console.readline()
method, returns string
type, not trown formatexception
, printed character in console successfully.
class program { static void main(string[] args) { int a; = convert.toint32(console.readline()); console.write(a); } }
the return type of console.read()
int
.
you call convert.toint32(int)
:
returns specified 32-bit signed integer; no actual conversion performed.
Comments
Post a Comment