Original article: understanding the differences between C #4 Dynamic (1)-var, object, and dynamic and the use of dynamic
Reading directory:
I. Why are the three of them
Ii. Reasons for arbitrary assignment
Iii. Usage of dynamic
Iv.
var,Object, the difference between the dynamic and the use of the reading directory: I. Why are they three two. The reason to be able to assign any value three. Use of dynamic Four. Considerations for using dynamic compare these three reasons
Var, dynamic, and vardynamic
Var and dynamic
If you have written a program using MVC, you should know that ViewBag is a data transfer tool for the front and back ends. Are you confused about the usage of ViewBag?
ViewBag.Mode1l=new
C # anonymous object (anonymous type), var, dynamic type dynamic,
This article is the prelude to the next article "C # reflection and optimization usage". It is not the foundation of the next article. If you are interested, please pay attention to
MVC var and dynamic, mvcvardynamic
If you have written a program using MVC, you should know that ViewBag is a data transfer tool for the front and back ends. Are you confused about the usage of ViewBag?
ViewBag.Mode1l=new object();ViewBag.Model2=new
Often people will take the keyword Var to compare with the dynamic. In fact, var and dynamic are completely two concepts that should not be compared at all. var is actually the "syntactic sugar" that is thrown at compile time, and once compiled, the
If you write a program in MVC, you should know that ViewBag is a data transfer tool for the front and back, so are you wondering about the usage of viewbag?viewbag.mode1l=Newobject(); Viewbag.model2=newobject(); Viewbag.model3=newobject();We know
From csharpfaq: What is the difference between "dynamic" and "object" keywords?
Let's take a quick look at the object keyword first. I won't talk too much about it, because it already exists in C #1.0. This keyword serves as a shortcut for
LookCode:
1:Dynamic A = 10;
2:A = a + 10;
3:Console. writeline (A. GetType ());
This code segment outputs system. int32, and the second line does not require type conversion, because the type is recognized at runtime. Dynamic uses the
With the development of C #, the content of the language continues to enrich, development becomes more convenient and fast, C # 's sharpness is undoubtedly obvious. C # language from birth is a strong type of language, this nature has not changed
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.