Is vs As operator keyword in C# Last Updated : 21 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The difference between is and as operators are as follows: The is operator is used to check if the run-time type of an object is compatible with the given type or not whereas as operator is used to perform conversion between compatible reference types or Nullable types. The is operator is of boolean type whereas as operator is not of 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. The is operator returns false if the given object is not of the same type whereas as operator return null if the conversion is not possible. The is operator is used for only reference, boxing, and unboxing conversions whereas as operator is used only for nullable, reference and boxing conversions Example of is operator: CSharp // C# program to illustrate the // use of is operator keyword using System; // taking a class public class P { } // taking a class // derived from P public class P1 : P { } // taking a class public class P2 { } // Driver Class public class GFG { // Main Method public static void Main() { // creating an instance // of class P P o1 = new P(); // creating an instance // of class P1 P1 o2 = new P1(); // checking whether 'o1' // is of type 'P' Console.WriteLine(o1 is P); // checking whether 'o1' is // of type Object class // (Base class for all classes) Console.WriteLine(o1 is Object); // checking whether 'o2' // is of type 'P1' Console.WriteLine(o2 is P1); // checking whether 'o2' is // of type Object class // (Base class for all classes) Console.WriteLine(o2 is Object); // checking whether 'o2' // is of type 'P' // it will return true as P1 // is derived from P Console.WriteLine(o2 is P1); // checking whether o1 // is of type P2 // it will return false Console.WriteLine(o1 is P2); // checking whether o2 // is of type P2 // it will return false Console.WriteLine(o2 is P2); } } Output: True True True True True False False Example of as operator: CSharp // C# program to illustrate the // concept of 'as' operator using System; // Classes class Y { } class Z { } class GFG { // Main method static void Main() { // creating and initializing object array object[] o = new object[5]; o[0] = new Y(); o[1] = new Z(); o[2] = "Hello"; o[3] = 4759.0; o[4] = null; for (int q = 0; q < o.Length; ++q) { // using as operator string str1 = o[q] as string; Console.Write("{0}:", q); // checking for the result if (str1 != null) { Console.WriteLine("'" + str1 + "'"); } else { Console.WriteLine("Is is not a string"); } } } } Output: 0:Is is not a string 1:Is is not a string 2:'Hello' 3:Is is not a string 4:Is is not a string Comment More infoAdvertise with us Next Article Is vs As operator keyword in C# A ankita_saini Follow Improve Article Tags : C# CSharp-keyword Similar Reads C# | as Operator Keyword In software development, typecasting is an inescapable thing. In many cases, developers need to convert an Object(Type) into another Object(Type) and sometimes he/she may get InvalidCastException. So, to overcome such types of exception C# provides the operator keyword as.The as operator is used to 3 min read C# | is Operator Keyword In the development of the software, typecasting is an inescapable thing. In many cases, one needs to convert an object(Type) into another object(Type) and sometimes got InvalidCastException. So, to overcome such types of exception C# provides is operator. The is operator is used to check if the run- 5 min read typeof Operator Keyword in C# The typeof is an operator keyword which is used to get a type at the compile-time. Or in other words, this operator is used to get the System.Type object for a type. This operator takes the Type itself as an argument and returns the marked type of the argument. Important points: The operand of typeo 3 min read var keyword in C# Keywords are the words in a language that are used for some internal process or represent some predefined actions. var is a keyword, it is used to declare an implicit type variable, that specifies the type of a variable based on initial value. Syntax: var variable_name = value; Example: Input: a = 6 2 min read ushort keyword in C# Keywords are the words in a language that are used for some internal process or represent some predefined actions. ushort is a keyword that is used to declare a variable which can store an unsigned integer value from the range 0 to 65,535. It is an alias of System.UInt16. Syntax: ushort variable_nam 2 min read Like