語言

QueryStringConverter.ConvertStringToValue(String, Type) 方法

定義

將查詢字串參數轉換為指定的型別。

public:
 virtual System::Object ^ ConvertStringToValue(System::String ^ parameter, Type ^ parameterType);
public virtual object ConvertStringToValue(string parameter, Type parameterType);
abstract member ConvertStringToValue : string * Type -> obj
override this.ConvertStringToValue : string * Type -> obj
Public Overridable Function ConvertStringToValue (parameter As String, parameterType As Type) As Object

參數

parameter
String

參數與值的字串形式。

parameterType
Type

該 Type 參數轉換為。

傳回

轉換後的參數。

例外狀況

所提供的字串格式不正確。

範例

以下程式碼說明如何將字串轉換成指定的型別。

if (converter.CanConvert(typeof(Int32)))
    converter.ConvertStringToValue("123", typeof(Int32));
If (converter.CanConvert(GetType(Int32))) Then
    converter.ConvertStringToValue("123", GetType(Int32))
End If

備註

若 為 parameterType 值型別,參數為 null,則回傳 的 parameterType 預設值。

適用於