RouteValueDictionary 建構函式

定義

初始化 RouteValueDictionary 類別的新執行個體。Initializes a new instance of the RouteValueDictionary class.

多載

RouteValueDictionary()

初始化 RouteValueDictionary 類別的新執行個體,這個執行個體是空白的。Initializes a new instance of the RouteValueDictionary class that is empty.

RouteValueDictionary(IDictionary<String,Object>)

初始化 RouteValueDictionary 類別的新執行個體,並從指定的集合加入項目。Initializes a new instance of the RouteValueDictionary class and adds elements from the specified collection.

RouteValueDictionary(Object)

初始化 RouteValueDictionary 類別的新執行個體,並從指定的物件加入以屬性為依據的值。Initializes a new instance of the RouteValueDictionary class and adds values that are based on properties from the specified object.

RouteValueDictionary()

初始化 RouteValueDictionary 類別的新執行個體,這個執行個體是空白的。Initializes a new instance of the RouteValueDictionary class that is empty.

public:
 RouteValueDictionary();
public RouteValueDictionary ();
Public Sub New ()

備註

您可以藉由RouteValueDictionary Add呼叫方法,將元素加入至物件。You can add elements to a RouteValueDictionary object by calling the Add method.

另請參閱

RouteValueDictionary(IDictionary<String,Object>)

初始化 RouteValueDictionary 類別的新執行個體,並從指定的集合加入項目。Initializes a new instance of the RouteValueDictionary class and adds elements from the specified collection.

public:
 RouteValueDictionary(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ dictionary);
public RouteValueDictionary (System.Collections.Generic.IDictionary<string,object> dictionary);
new System.Web.Routing.RouteValueDictionary : System.Collections.Generic.IDictionary<string, obj> -> System.Web.Routing.RouteValueDictionary
Public Sub New (dictionary As IDictionary(Of String, Object))

參數

dictionary
IDictionary<String,Object>

其項目將複製到新集合的集合。A collection whose elements are copied to the new collection.

例外狀況

dictionarynulldictionary is null.

dictionary 包含一個或多個重複的索引鍵。dictionary contains one or more duplicate keys.

備註

物件中的RouteValueDictionary每個索引鍵都必須是唯一的。Every key in a RouteValueDictionary object must be unique. RouteValueDictionary類別使用不區分大小寫的序數比較。The RouteValueDictionary class uses case-insensitive ordinal comparison. 如需詳細資訊,請參閱OrdinalIgnoreCaseFor more information, see OrdinalIgnoreCase. 索引鍵不可以null是。A key cannot be null.

另請參閱

RouteValueDictionary(Object)

初始化 RouteValueDictionary 類別的新執行個體,並從指定的物件加入以屬性為依據的值。Initializes a new instance of the RouteValueDictionary class and adds values that are based on properties from the specified object.

public:
 RouteValueDictionary(System::Object ^ values);
public RouteValueDictionary (object values);
new System.Web.Routing.RouteValueDictionary : obj -> System.Web.Routing.RouteValueDictionary
Public Sub New (values As Object)

參數

values
Object

物件,包含將以項目形式加入新集合中的屬性。An object that contains properties that will be added as elements to the new collection.

範例

下列範例顯示如何Route建立物件,以及如何Constraints設定、 DataTokensDefaults屬性。The following example shows how to create a Route object and how to set the Constraints, DataTokens, and Defaults properties.

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    Route reportRoute = new Route("{locale}/{year}", new ReportRouteHandler());
    reportRoute.Defaults = new RouteValueDictionary { { "locale", "en-US" }, { "year", DateTime.Now.Year.ToString() } };
    reportRoute.Constraints = new RouteValueDictionary { { "locale", "[a-z]{2}-[a-z]{2}" }, { "year", @"\d{4}" } };
    reportRoute.DataTokens = new RouteValueDictionary { { "format", "short" } };
    routes.Add(reportRoute);
}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    RegisterRoutes(RouteTable.Routes)
End Sub

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    Dim urlPattern As String
    Dim reportRoute As Route
    
    urlPattern = "{locale}/{year}"
    
    reportRoute = New Route(urlPattern, New ReportRouteHandler)
    reportRoute.Defaults = New RouteValueDictionary(New With {.locale = "en-US", .year = DateTime.Now.Year.ToString()})
    reportRoute.Constraints = New RouteValueDictionary(New With {.locale = "[a-z]{2}-[a-z]{2}", .year = "\d{4}"})
    reportRoute.DataTokens = New RouteValueDictionary(New With {.format = "short"})

    routes.Add(reportRoute)
End Sub

備註

根據字典的相等RouteValueDictionary比較子,物件中的每個索引鍵都必須是唯一的。Every key in a RouteValueDictionary object must be unique according to the dictionary's equality comparer. RouteValueDictionary類別使用不區分大小寫的序數比較。The RouteValueDictionary class uses case-insensitive ordinal comparison. 如需詳細資訊,請參閱OrdinalIgnoreCaseFor more information, see OrdinalIgnoreCase. 索引鍵不可以null是。A key cannot be null.

另請參閱

適用於