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)05/31 Report--
Most people do not understand the knowledge points of this article "how to apply named parameters and optional parameters in C#", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article, let's take a look at this "how to apply named parameters and optional parameters in C#" article.
I. brief introduction
The parameters of the design method are that some and all parameters can be assigned default values, and then when calling these methods, you can choose not to provide some arguments and use the default values defined by the parameters, in addition, you can also pass the arguments by specifying the parameter name when calling the method.
Code case class Program {private static int s = 0; private static int swatches = 0; private static void Mothed (int x = 9, string s = "A", DateTime dt= default (DateTime), Guid guid= new Guid ()) {Console.WriteLine ("x = {0}, s = {1}, dt= {2}, guid= {3}", x, s, dt, guid) } static void Main (string [] args) {Mothed (); / equivalent to Mothed (9, "A", default (Datetime), new Guid ()) Mothed (8, "X"); / / equivalent to Mothed (8, "X", default (Datetime), new Guid ()) Mothed (5, guid: Guid.NewGuid (), dt: DateTime.Now) / equivalent to Mothed (5, "A", DateTime.Now,Guid.NewGuid ()) Mothed (sroomnails, s_n++.ToString ()); / / equivalent to Mothed (0, "1", default (Datetime), new Guid ()); Mothed (s: (scoundrel +) .ToString (), x: sprinter +) / / is equivalent to the following two lines of code. Note that the order of the parameters here is independent of the order of the parameters, corresponding to / / string T1 = "2"; / / int32 t2quo3; / / Mothed (t2dint T1) default (Datetime), new Guid ()}}
When you pass arguments to a method, the compiler evaluates the arguments from left to right. In the fourth call to Mothed, the current default value of sroomn is 0, which is incremented and then equals 1 to string to s, and then continues to be incremented to 2 (sroomn _ increment + first used and then incremented) to x.
The above is the content of this article on "how to apply named parameters and optional parameters in C#". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, 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.