In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What this article shares with you is about the concepts related to .NET Framework implicit type variables. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.
There is a new feature in .NET Framework called .NET Framework implicitly typed variables. We will introduce the relevant knowledge in detail in this article. With vs 2008, you can declare a variable and let the compiler implicitly determine the type of the variable. LINQ uses this feature to process the created variables. To use this feature, use the var keyword:
Var Xero5
When using this statement, the compiler uses 5 to determine the type of the variable. This means that the statement should actually look like this:
Int Xero5
.net Framework implicit type variables are strongly typed, and var will be replaced by the determined type after the compiler compiles.
Implicitly typed variable keywords and var in js:
Javascript is a weakly typed language, and variables in javascript (including those declared with var) can be typed, as shown in the following javascript:
Var s = "abcd"; sound3; alert (s)
The above code * * assigns a string to s and the second line assigns an integer to it. There is nothing wrong with such code in javascript. However, in C # 3.0, once the var variable is initialized and the type is determined, the type cannot be changed. Such as the following code cannot be compiled:
Var ss = "abcd"; ss = 44
To sum up, there are four characteristics when defining variables using the .NET Framework implicit type variable var:
1. Must be initialized at definition time. That is, it must be in the form var s = "abcd", not in the following form:
Var s; s = "abcd"
It is inferred by the compiler from the context, so all uses that cannot be inferred by the compiler are wrong. For example, you can't use it like this: var nullValue = null; because null is nothing, it's a null pointer, it's an uncertain thing. You can't use it this way: var I = 5 th I = "abc"; how does the compiler infer that it is an integer based on * assignments, but then assign a string to it?
The 2.var requirement is a local variable.
3. Defining variables using the .NET Framework implicitly typed variable var is different from object in that it is exactly the same as defining variables in a strongly typed way. However, the author suggests that if you know the type of variables in advance, try to use strongly typed methods to declare variables. Otherwise, it will be difficult for developers to determine what type a variable is due to the heavy use of var. This is not conducive to the maintenance and upgrade of the program. (implicit type local variables are used only when the compiler can infer and people cannot infer, and it is not recommended that we manually infer. Explicitly declaring variable types can enhance the readability of the code, which is a good programming habit. Don't be useful just because C # 3.0 provides such a feature. )
Although the .NET Framework implicitly typed variable var has its advantages and disadvantages, the author personally believes that if you convert a dynamic language to a C # language, you can consider using var to define variables. This is because dynamic languages have no types, and if you want to convert them to a strongly typed C # language, you must specify a type to the variable, but it is difficult to determine the type in advance, so it is better to specify it as var, and then the C # compiler determines the specific type of the variable. So what if, during the conversion process, it is found that the variables of the dynamic language have changed their types? This can use "anonymous class" to solve this problem.
These are the concepts related to implicitly typed variables in .NET Framework, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.