Narrowing (Visual Basic)Narrowing (Visual Basic)

表示轉換運算子 (CType) 將類別或結構轉換成可能無法保留一些可能的值,原始的類別或結構的類型。Indicates that a conversion operator (CType) converts a class or structure to a type that might not be able to hold some of the possible values of the original class or structure.

轉換以縮小關鍵字Converting with the Narrowing Keyword

轉換程序必須指定Public Shared除了NarrowingThe conversion procedure must specify Public Shared in addition to Narrowing.

縮小轉換執行不一定成功在執行階段,並可能會失敗或者會造成資料遺失。Narrowing conversions do not always succeed at run time, and can fail or incur data loss. 範例包括LongIntegerStringDate,並為衍生類型的基底型別。Examples are Long to Integer, String to Date, and a base type to a derived type. 這個最後一個轉換縮小,因為基底型別可能不會包含衍生型別的所有成員,而且不是衍生型別的執行個體。This last conversion is narrowing because the base type might not contain all the members of the derived type and thus is not an instance of the derived type.

如果Option StrictOn,使用程式碼必須使用CType所有的縮小轉換。If Option Strict is On, the consuming code must use CType for all narrowing conversions.

Narrowing關鍵字可以用在此內容中:The Narrowing keyword can be used in this context:

Operator 陳述式Operator Statement

另請參閱See also