What are the difference between Object, Var and dynamic keyword in C# ?


When I was giving the interview I was getting this question in all interview. So I am sharing this short answer for everyone.

This all keywords looks like used for same purpose and there are some differences in each one.

Advertisements

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);
}

}
}