In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use the dynamic type of the new feature of Visual C # 2010. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In most cases, the dynamic and object types are similar, but at compile time, the dynamic type is assumed to support any operation, that is, an object of type dynamic can be an Office object, a COM object, or a DOM object, and a run-time exception will be thrown if it is found at run time that the object is not the expected object.
Because an object is defined as a dynamic type, it is legal to write any call in the code at compile time (this cannot be true when declared as an object type). For example, the following code can be compiled:
After running, it is found that obj does not support the UpdateWordDocument method, so an exception will be thrown:
The result of most dynamic type operations is still dynamic type, for example, when writing the following code, the smart prompt will show that the variable type is dynamic:
Operations that include conversions from dynamic types to other types, or take dynamic types as constructor parameters, do not return dynamic types, such as the following code:
C is not of type dynamic at this time.
Developers can easily convert between dynamic and non-dynamic types, precisely because dynamic types are considered to support any operation at compile time, and only need to ensure that the conversion between them is the correct data type conversion, otherwise an error will occur at run time. For example, the following code:
Using a method that parses at run time rather than compile time through dynamic type parameters, a new dynamic language runtime (DLR) is introduced in the .NET Framework 4 Beta1, which provides support for dynamic types in C # and provides implementations of dynamic languages such as IronPython and IronRuby.
Visual C # 2010 facilitates interaction with COM API using dynamic types and naming and optional parameters. Many COM methods take various types of parameters and usually return object type values, and developers need to do type conversions for further operations. In .NET Framework 4, if the / link switch is used to compile the program, the dynamic type allows the object type to be treated as a dynamic type when COM is called, thus avoiding type conversions. For example, the following code (this code is an excerpt, the machine reason has not been tested by me)
Thank you for reading! This is the end of this article on "how to use the dynamic type of the new features of Visual C # 2010". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.