CodeCastExpression CodeCastExpression CodeCastExpression CodeCastExpression Class

定義

表示一個轉換為資料型別或介面的運算式。Represents an expression cast to a data type or interface.

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

範例

這個範例示範如何使用CodeCastExpressionSystem.Int32值轉換成System.Int64資料類型。This example demonstrates using a CodeCastExpression to cast a System.Int32 value to a System.Int64 data type.

// 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可以用來代表轉換成不同資料類型或介面的運算式。CodeCastExpression can be used to represent an expression cast to a different data type or interface.

屬性會指出要CodeExpression轉換的。 ExpressionThe Expression property indicates the CodeExpression to cast. TargetType屬性會指出要轉換成的型別。The TargetType property indicates the type to cast to.

建構函式

CodeCastExpression() CodeCastExpression() CodeCastExpression() CodeCastExpression()

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

CodeCastExpression(CodeTypeReference, CodeExpression) CodeCastExpression(CodeTypeReference, CodeExpression) CodeCastExpression(CodeTypeReference, CodeExpression) CodeCastExpression(CodeTypeReference, CodeExpression)

使用指定的目的型別和運算式,初始化 CodeCastExpression 類別的新執行個體。Initializes a new instance of the CodeCastExpression class using the specified destination type and expression.

CodeCastExpression(String, CodeExpression) CodeCastExpression(String, CodeExpression) CodeCastExpression(String, CodeExpression) CodeCastExpression(String, CodeExpression)

使用指定的目的型別和運算式,初始化 CodeCastExpression 類別的新執行個體。Initializes a new instance of the CodeCastExpression class using the specified destination type and expression.

CodeCastExpression(Type, CodeExpression) CodeCastExpression(Type, CodeExpression) CodeCastExpression(Type, CodeExpression) CodeCastExpression(Type, CodeExpression)

使用指定的目的型別和運算式,初始化 CodeCastExpression 類別的新執行個體。Initializes a new instance of the CodeCastExpression class using the specified destination type and expression.

屬性

Expression Expression Expression Expression

取得或設定要轉型的運算式。Gets or sets the expression to cast.

TargetType TargetType TargetType TargetType

取得或設定轉型的目的型別。Gets or sets the destination type of the cast.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱