What is the difference between Is and as Keyword in C# ?


Hi

One time i got this question in interview. Answer of this question , i have implemented in this code like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//The is operator is used to check whether the run-time type of an object is compatible with a given

object num=10;
if (num is int)
{
Response.Write(“Num is integer”);
}

//The as operator is used to perform conversions between compatible types.

object ss = “This sis the string”;
string str = string.Empty;
if (ss is string)
{
str = ss as string;

Response.Write(str);
}

}
}

Advertisement

2 thoughts on “What is the difference between Is and as Keyword in C# ?

  1. Vigneshwaran July 18, 2013 / 6:30 am

    Sir can u please send code for send message from asp.net to mobile.. I need his for my mini project…

    • Chandra Dev July 19, 2013 / 7:24 pm

      Hi

      There would not be the unique code for sending sms. We have to register on their site then we will get the api code. There will be instruction to implement in your application. It will paid service.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.