CodeCastExpression 類別

定義

表示一個轉換為資料型別或介面的運算式。

public ref class CodeCastExpression : System::CodeDom::CodeExpression
public class CodeCastExpression : System.CodeDom.CodeExpression
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeCastExpression : System.CodeDom.CodeExpression
type CodeCastExpression = class
    inherit CodeExpression
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeCastExpression = class
    inherit CodeExpression
Public Class CodeCastExpression
Inherits CodeExpression
繼承
CodeCastExpression
屬性

範例

此範例示範如何使用 CodeCastExpression 將值System.Int64轉換成System.Int32數據類型。

// This CodeCastExpression casts an Int32 of 1000 to an Int64.        

// targetType parameter indicating the target type of the cast.
// The CodeExpression to cast, here an Int32 value of 1000.
CodeCastExpression^ castExpression = gcnew CodeCastExpression( "System.Int64",gcnew CodePrimitiveExpression( 1000 ) );

// A C# code generator produces the following source code for the preceeding example code:
// ((long)(1000));
// This CodeCastExpression casts an Int32 of 1000 to an Int64.
CodeCastExpression castExpression = new CodeCastExpression(
    // targetType parameter indicating the target type of the cast.
    "System.Int64",
    // The CodeExpression to cast, here an Int32 value of 1000.
    new CodePrimitiveExpression(1000) );

// A C# code generator produces the following source code for the preceeding example code:

// ((long)(1000));
' This CodeCastExpression casts an Int32 of 1000 to an Int64.		
Dim castExpression As New CodeCastExpression( _
    "System.Int64", New CodePrimitiveExpression(1000) )
    
' A Visual Basic code generator produces the following source code for the preceeding example code:

' CType(1000,Long)

備註

CodeCastExpression 可用來表示轉換成不同數據類型或介面的表達式。

屬性 Expression 表示要轉換的 CodeExpression 。 屬性 TargetType 會指出要轉換成的型別。

建構函式

CodeCastExpression()

初始化 CodeCastExpression 類別的新執行個體。

CodeCastExpression(CodeTypeReference, CodeExpression)

使用指定的目的型別和運算式,初始化 CodeCastExpression 類別的新執行個體。

CodeCastExpression(String, CodeExpression)

使用指定的目的型別和運算式,初始化 CodeCastExpression 類別的新執行個體。

CodeCastExpression(Type, CodeExpression)

使用指定的目的型別和運算式,初始化 CodeCastExpression 類別的新執行個體。

屬性

Expression

取得或設定要轉型的運算式。

TargetType

取得或設定轉型的目的型別。

UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱