QueryStringConverter.ConvertStringToValue(String, Type) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將查詢字串參數轉換為指定的型別。
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
參數與值的字串形式。
傳回
轉換後的參數。
例外狀況
所提供的字串格式不正確。
範例
以下程式碼說明如何將字串轉換成指定的型別。
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 預設值。