In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the essence of Linq query". In daily operation, I believe many people have doubts about the nature of Linq query. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the essence of Linq query?" Next, please follow the editor to study!
1. Automatic attribute
Class Class {/ / id 2.0 attribute / / private int _ id; / / public int ID / / {/ / get {/ / return _ id; / /} / / set / / {/ / _ id = value; / /} /} / / get set 3.0 attribute can add an access modifier public int ID {get; private set;} public string Name {get; set } public Class (int id) {/ / attributes with private can only be accessed inside the class this.ID = id;}}
The essence of Linq query: it is no different from the original properties, but simplifies the syntax.
two。 Initializer
Private static void Initializer () {/ / Class 2.0 object initialization / / Class c = new Class (1); / / c.Name = "* Class 1"; / / Cure 3.0 object initializer Class c = new Class (1) {Name = "* Class 1"}; / / Cure 2.0 collection initialization / / ClassCollection list = class 1 (); / / list.Add (c) / / Collection initializer ClassCollection list = new ClassCollection {new Class (1) {Name= "* Class 1"}, new Class (2) {Name= "* Class 2"}}; foreach (Class item in list) {Console.WriteLine (item.ID + "" + item.Name);}}
The essence of Linq query: it is no different from the original constructor initialization or construction through attribute initialization, which simplifies the syntax.
3. Local variables with implicit types
Private static void Var () {var icompiler 1; / / the compiled result is actually int iTunes 1; var is not a dynamic variable, its type is actually c # compiler int / / var I = DateTime.Now; / / compiled by context, but unlike JavaScript, var d = DateTime.Now; / / = supports various types of var a = new int [] {1,2,3}. / / var also supports the type of array foreach (var item in a) / / item inferred by the C # compiler to know that it is int {Console.WriteLine (I);} / var x; / / error, there is no initializer / / var y = {1,2,3}; / / error, collection initializer / / var z = null is not allowed / / error. Null type is not allowed.
Linq query essence: var is not a dynamic type, C # is still a static language, the introduction of var is convenient for us to write code, regardless of the type of assignment expression after "=", it is up to the compiler to infer and generate the corresponding type.
At this point, the study on "what is the essence of Linq query" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.