.Net Interview Questions and Answers

Search:

What is the difference between VAR and Dynamic keyword? ( .NET Interview questions with answers)

By : Shiv Prasad Koirala | Nov 27th, 2013 | Views : 3327 | Comments : 0 Bookmark and Share

In case you are new to .NET Var keyword please first view this .NET interview question video which explains why we need .NET VAR keyword.

 

 

 

Note :- Comparing VAR and Dynamic keyword is like comparing Apples and oranges. Many people confuse VAR with the variant datatype of VB6 and there's where interviewer tries to confuse you. But there is absolute no connection of var c# keyword with variant of VB6.

 

Var is early binded (statically checked) while dynamic is late binded (dynamically evaluated).

 

Var keyword looks at your right hand side data and then during compile time it decides the left hand data type.In other words var keyword just saves you typing lot of things.

 

                                                                       

 

On the other hand dynamic keyword is for completely different purpose. Dynamic objects are evaluated during runtime. For instance in the below code the "Length" property exists or not is evaluated during runtime.

 

dynamic z = "Dynamic";

y = z.Length; // Is Length present or not checked during runtime

 

If for some reason you mistype the "Length" property to "length" (Small "|") you would end up in to a runtime exception as shown in the below figure.

 

                                

 

So in short sentence Var does static check while dynamic evaluates and checks during runtime.

 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

Article Categories

Learn in Hindi