2010-08-31 490 views
0

我已將我的MVC項目和VS2008升級到MVC2和VS2010。當爲控制器操作返回ActionResult時,我注意到intellisense給出了view:選項。這是關於什麼的?是什麼意思:是什麼意思?

回答

3

這是可選參數。可選參數只是讓您省略參數值和命名參數讓我們以任意順序輸入它們。

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"); 
}