I've upgraded my MVC project and VS2008 to MVC2 and VS2010. When returning ActionResult for controller actions I notice the intellisense gives view:
option. What is this about?
views:
61answers:
1
+3
A:
This is optional arguments. Optional arguments simply let’s you omit argument values and named arguments let’s you enter them in any order you’d like.
public int Test(int a, int b = 1, int c = 2, int d = 3) {
return a + b + c + d;
}
public string Hello(string name = "World") {
return "Hello, " + name + "!";
}
public void Main() {
Test(0); //Test(0,1,2,3)
Test(0, c: 5); //Test(0,1,5,3)
Test(d: 5, a: 0); //Test(0,1,2,5)
Hello(); //Hello("World");
}
Torbjörn Hansson
2010-08-31 13:55:26