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

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -