yandex
loader

please wait

  • Harsh Vashishth Mar-13-2019 05:50:09 AM ( 1 week ago )
    long? i = 10000;
    int? s = i as int?;

    Why is it giving me a null in s variable? I know that casting it using int? s = (int?)i; will work fine but why can't I use an as operator?

  • Imran Malik Mar-13-2019 05:51:32 AM ( 1 week ago )

    The code is equivalent to the following expression except that the expression variable is evaluated only one time.

    expression is type ? (type)expression : (type)null

    Since i is int? is false the as keyword will return (int?)null.

Please login

Similar Discussion

Recommended For You