Home > Interview Questions > C#.NET > What is the difference between IS and AS operator in C#?

What is the difference between IS and AS operator in C#?

by Thamil   on 04/10/2015   Category: C#.NET   |  Level: Intermediate   |  Views: 527    |  Points: 25     |  Gold 


IS operator is used to verify the compatibility of an object and returns the Boolean value if yes then return true, if no then return false.
AS operator is used for casting of object to a specific type.

IS operator sample code
string num = "10";
if (num is string) // check whether num is string or not

{
}


AS operator sample code
Object obj = new Object(); // Creates a new Object obj
Student objst = obj as Student; // If this cast fails then null would assigned into objst.
if (objst != null)
{
}



« What is Global.asax file in asp.net web application?
» Which types are stored in stack and heap in C#?
Post Question  |  Question Home

Recent Posts

User Responses


No response found, be the first to review this question.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts

1 3D model and 2D View New! Forum