c# - Why must write O AS INT and can't write (INT)O -


I like to use the as operator in John Skeet's book with such a type Example found, which allows the zero value.

  using the system; Class A {static white printAUscient 32 (object o) {int? O; as nullable = int ;; Can not write // int? Nullable = (int?) O console Wrightite (nullable.HasValue? Nullable.Value.ToString (): "Zero"); } Fixed zero main () {PrintValueAsInt32 (5); PrintValueAsInt32 ("some string"); }}   

I can not understand why I can not write int? Nullable = (int?) O ? When I try to do this, I'm getting an exception.

Because checking first cast Types are not variable for each other, then it only gives zero and avoids invalid cut exception .

When you are passing a string in the second call in the second call, which is not variable for int, then try to use the clear artist Time Receiving an Exception

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -