Gul Md Ershad
Why should not use AS operator for the typecating in Value type? float c = 20; e.g. int a = c as int; its wrong. Why?
By Gul Md Ershad in .NET on Dec 02 2014
  • Gul Md Ershad
    Dec, 2014 2

    As operator set null value if it is unable to typecast. Value type can't accept null except string. So, as operator is not being used with value type in c#.

    • 1
  • Pankaj  Kumar Choudhary
    May, 2015 27

    As operator is used mainly with References type or null able type because if conversion is not possible then it return NULL value but int can not store it so we can not us "AS" operator with non-nullable value type

    • 0
  • Vaibhav Singh
    Mar, 2015 11

    Note that 'as' operator relies on implicit typecasting. Using as implies that you actually know the type of the variable at the compile time (or can assert that it will be what you expect). Rest is correctly mentioned by Gul Md Ershad.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS