c# - How do I put optional parameters in methods? -
In what methods is it possible to declare optional parameters?
In Delphi, for example, I can
: Process testing (page 1: integer; p2: integer; p3: integer I can call it with four criteria or two criteria when I call the function: Code> test (2,3); // p3 = 2, p4 = 4. test (2,3,4,5); // p3 = 4, p4 = 5; How is this possible in C #?
I'm afraid that from C # 1 to 3 this is not possible. However, the good news is that because it is a very demanding feature (though there is definitely something that does not want to see it), Microsoft finally c # 4
C # 4 syntax is as follows:
public static void zero (string s = "hello world!") {Console.WriteLine (s); } Usage:
SayHello (); // Print "Hello World!" SayHello ("Hello."); // Print "Hello." Sehelo (S: "Hello."); // Print "Hello." (The last example uses a named argument, which is not really necessary in this case, but you have several optional parameters.)
You Can read more about that topic about
Comments
Post a Comment