What is difference between IS and AS operator keyboard in C#

Опубликовано: 05 Октябрь 2024
на канале: OrBit of the CodinG
64
5

What is difference between IS and AS operator keyboard in C#

IS Oprator:
The is operator is used to check if the run-time type of an object is compatible with the given type or not.

AS Oprator:
As keyword is helpful when we want to convert an object from one type to another type.

Differences:
The Is Oprator returns False if the given object is not in the same type whereas as oprator retuen null value.
IS keyword is helpful to check if the object is that type or not
AS keyword is helpful too if we want to convert one type to another type.
IS keyword type is boolean and AS keyword is not a boolean type.
The is operator returns true if the given object is of the same type whereas as operator returns the object when they are compatible with the given type.