diff --git a/.openpublishing.redirection.visual-basic.json b/.openpublishing.redirection.visual-basic.json index 59d2ea1d847a6..f1eab0b895d91 100644 --- a/.openpublishing.redirection.visual-basic.json +++ b/.openpublishing.redirection.visual-basic.json @@ -1286,6 +1286,11 @@ { "source_path_from_root": "/docs/visual-basic/sample-applications.md", "redirect_url": "/samples/browse/?languages=vb" + }, + { + "source_path_from_root": "/docs/visual-basic/language-reference/functions/ctype-function.md", + "redirect_url": "/dotnet/visual-basic/language-reference/operators/ctype-operator", + "redirect_document_id": true } ] } diff --git a/docs/framework/data/adonet/sql/linq/basic-data-types.md b/docs/framework/data/adonet/sql/linq/basic-data-types.md index 65a67339b9963..86655a05832ee 100644 --- a/docs/framework/data/adonet/sql/linq/basic-data-types.md +++ b/docs/framework/data/adonet/sql/linq/basic-data-types.md @@ -10,7 +10,7 @@ Because LINQ to SQL queries translate to Transact-SQL before they are executed o ## Casting - Implicit or explicit casts are enabled from a source CLR type to a target CLR type if there is a similar valid conversion within SQL Server. For more information about CLR casting, see [CType Function](../../../../../visual-basic/language-reference/functions/ctype-function.md) (Visual Basic) and [Type-testing and cast operators](../../../../../csharp/language-reference/operators/type-testing-and-cast.md). After conversion, casts change the behavior of operations performed on a CLR expression to match the behavior of other CLR expressions that naturally map to the destination type. Casts are also translatable in the context of inheritance mapping. Objects can be cast to more specific entity subtypes so that their subtype-specific data can be accessed. + Implicit or explicit casts are enabled from a source CLR type to a target CLR type if there is a similar valid conversion within SQL Server. For more information about CLR casting, see [CType Function](../../../../../visual-basic/language-reference/operators/ctype-operator.md) (Visual Basic) and [Type-testing and cast operators](../../../../../csharp/language-reference/operators/type-testing-and-cast.md). After conversion, casts change the behavior of operations performed on a CLR expression to match the behavior of other CLR expressions that naturally map to the destination type. Casts are also translatable in the context of inheritance mapping. Objects can be cast to more specific entity subtypes so that their subtype-specific data can be accessed. ## Equality Operators diff --git a/docs/visual-basic/language-reference/data-types/boolean-data-type.md b/docs/visual-basic/language-reference/data-types/boolean-data-type.md index 505fd6b129e4a..f5e72ddfe4fa9 100644 --- a/docs/visual-basic/language-reference/data-types/boolean-data-type.md +++ b/docs/visual-basic/language-reference/data-types/boolean-data-type.md @@ -60,4 +60,4 @@ End If - [Conversion Summary](../keywords/conversion-summary.md) - [Efficient Use of Data Types](../../programming-guide/language-features/data-types/efficient-use-of-data-types.md) - [Troubleshooting Data Types](../../programming-guide/language-features/data-types/troubleshooting-data-types.md) -- [CType Function](../functions/ctype-function.md) +- [CType Operator](../operators/ctype-operator.md) diff --git a/docs/visual-basic/language-reference/error-messages/latebound-overload-resolution-cannot-be-applied.md b/docs/visual-basic/language-reference/error-messages/latebound-overload-resolution-cannot-be-applied.md index 22b3baf8e6939..3e5d612be9966 100644 --- a/docs/visual-basic/language-reference/error-messages/latebound-overload-resolution-cannot-be-applied.md +++ b/docs/visual-basic/language-reference/error-messages/latebound-overload-resolution-cannot-be-applied.md @@ -65,4 +65,4 @@ Each of the preceding lines of code explicitly casts the `Object` variable `o1` - [Procedure Overloading](../../programming-guide/language-features/procedures/procedure-overloading.md) - [Overload Resolution](../../programming-guide/language-features/procedures/overload-resolution.md) -- [CType Function](../functions/ctype-function.md) +- [CType Operator](../operators/ctype-operator.md) diff --git a/docs/visual-basic/language-reference/functions/conversion-functions.md b/docs/visual-basic/language-reference/functions/conversion-functions.md index b5d29a9b4549b..e7703b9d2644a 100644 --- a/docs/visual-basic/language-reference/functions/conversion-functions.md +++ b/docs/visual-basic/language-reference/functions/conversion-functions.md @@ -34,7 +34,7 @@ ms.assetid: 8a8fb553-a8ac-424e-8103-26eea25eaa71 - [CShort Function](type-conversion-functions.md) - [CSng Function](type-conversion-functions.md) - [CStr Function](type-conversion-functions.md) -- [CType Function](ctype-function.md) +- [CType Operator](../operators/ctype-operator.md) - [CUInt Function](type-conversion-functions.md) - [CULng Function](type-conversion-functions.md) - [CUShort Function](type-conversion-functions.md) diff --git a/docs/visual-basic/language-reference/functions/index.md b/docs/visual-basic/language-reference/functions/index.md index 2fb2516eb5b15..8a1ffde8d747f 100644 --- a/docs/visual-basic/language-reference/functions/index.md +++ b/docs/visual-basic/language-reference/functions/index.md @@ -24,8 +24,6 @@ The topics in this section contain tables of the Visual Basic run-time member fu [Type Conversion Functions](type-conversion-functions.md) - [CType Function](ctype-function.md) - ## Related Sections [Visual Basic Language Reference](../index.md) diff --git a/docs/visual-basic/language-reference/functions/type-conversion-functions.md b/docs/visual-basic/language-reference/functions/type-conversion-functions.md index 74845dfc696c2..3e64554f4732b 100644 --- a/docs/visual-basic/language-reference/functions/type-conversion-functions.md +++ b/docs/visual-basic/language-reference/functions/type-conversion-functions.md @@ -188,9 +188,9 @@ Dim i3 As Integer = CInt(Math.Round(s)) ' Result: 174 If you need to convert to or from a string representation of a value in a format other than the one specified by your locale, you cannot use the Visual Basic type conversion functions. To do this, use the `ToString(IFormatProvider)` and `Parse(String, IFormatProvider)` methods of that value's type. For example, use when converting a string to a `Double`, and use when converting a value of type `Double` to a string. -## CType Function +## CType Operator -The [CType Function](ctype-function.md) takes a second argument, `typename`, and coerces `expression` to `typename`, where `typename` can be any data type, structure, class, or interface to which there exists a valid conversion. +The [CType Operator](../operators/ctype-operator.md) takes a second argument, `typename`, and coerces `expression` to `typename`, where `typename` can be any data type, structure, class, or interface to which there exists a valid conversion. For a comparison of `CType` with the other type conversion keywords, see [DirectCast Operator](../operators/directcast-operator.md) and [TryCast Operator](../operators/trycast-operator.md). diff --git a/docs/visual-basic/language-reference/keywords/conversion-summary.md b/docs/visual-basic/language-reference/keywords/conversion-summary.md index 7803cdd7cc2ab..54a12f7ef2d75 100644 --- a/docs/visual-basic/language-reference/keywords/conversion-summary.md +++ b/docs/visual-basic/language-reference/keywords/conversion-summary.md @@ -20,7 +20,7 @@ Visual Basic language keywords and run-time library members are organized by pur |Convert date to serial number.|, | |Convert decimal number to other bases.|, | |Convert number to string.|, | -|Convert one data type to another.|[CBool](../functions/type-conversion-functions.md), [CByte](../functions/type-conversion-functions.md), [CDate](../functions/type-conversion-functions.md), [CDbl](../functions/type-conversion-functions.md), [CDec](../functions/type-conversion-functions.md), [CInt](../functions/type-conversion-functions.md), [CLng](../functions/type-conversion-functions.md), [CSng](../functions/type-conversion-functions.md), [CShort](../functions/type-conversion-functions.md), [CStr](../functions/type-conversion-functions.md), [CType](../functions/ctype-function.md), , | +|Convert one data type to another.|[CBool](../functions/type-conversion-functions.md), [CByte](../functions/type-conversion-functions.md), [CDate](../functions/type-conversion-functions.md), [CDbl](../functions/type-conversion-functions.md), [CDec](../functions/type-conversion-functions.md), [CInt](../functions/type-conversion-functions.md), [CLng](../functions/type-conversion-functions.md), [CSng](../functions/type-conversion-functions.md), [CShort](../functions/type-conversion-functions.md), [CStr](../functions/type-conversion-functions.md), [CType](../operators/ctype-operator.md), , | |Convert date to day, month, weekday, or year.|, , , | |Convert time to hour, minute, or second.|, , | |Convert string to ASCII value.|, | diff --git a/docs/visual-basic/language-reference/modifiers/narrowing.md b/docs/visual-basic/language-reference/modifiers/narrowing.md index 1614e1d813929..04730bbb6c0e1 100644 --- a/docs/visual-basic/language-reference/modifiers/narrowing.md +++ b/docs/visual-basic/language-reference/modifiers/narrowing.md @@ -34,5 +34,5 @@ Indicates that a conversion operator (`CType`) converts a class or structure to - [Widening](widening.md) - [Widening and Narrowing Conversions](../../programming-guide/language-features/data-types/widening-and-narrowing-conversions.md) - [How to: Define an Operator](../../programming-guide/language-features/procedures/how-to-define-an-operator.md) -- [CType Function](../functions/ctype-function.md) +- [CType Operator](../operators/ctype-operator.md) - [Option Strict Statement](../statements/option-strict-statement.md) diff --git a/docs/visual-basic/language-reference/modifiers/widening.md b/docs/visual-basic/language-reference/modifiers/widening.md index 07c1fd099aaad..2ec9e57e68a58 100644 --- a/docs/visual-basic/language-reference/modifiers/widening.md +++ b/docs/visual-basic/language-reference/modifiers/widening.md @@ -36,6 +36,6 @@ Indicates that a conversion operator (`CType`) converts a class or structure to - [Narrowing](narrowing.md) - [Widening and Narrowing Conversions](../../programming-guide/language-features/data-types/widening-and-narrowing-conversions.md) - [How to: Define an Operator](../../programming-guide/language-features/procedures/how-to-define-an-operator.md) -- [CType Function](../functions/ctype-function.md) +- [CType Operator](../operators/ctype-operator.md) - [Option Strict Statement](../statements/option-strict-statement.md) - [How to: Define a Conversion Operator](../../programming-guide/language-features/procedures/how-to-define-a-conversion-operator.md) diff --git a/docs/visual-basic/language-reference/functions/ctype-function.md b/docs/visual-basic/language-reference/operators/ctype-operator.md similarity index 78% rename from docs/visual-basic/language-reference/functions/ctype-function.md rename to docs/visual-basic/language-reference/operators/ctype-operator.md index 08c7b28ce1110..99f11fdfb1071 100644 --- a/docs/visual-basic/language-reference/functions/ctype-function.md +++ b/docs/visual-basic/language-reference/operators/ctype-operator.md @@ -1,18 +1,18 @@ --- -description: "Learn more about: CType Function (Visual Basic)" -title: "CType Function" +description: "Learn more about: CType Operator (Visual Basic)" +title: "CType Operator" ms.date: 07/20/2015 f1_keywords: - "vb.CType" helpviewer_keywords: - "expression conversion results" - "explicit data type conversions [Visual Basic]" - - "CType function" + - "CType operator" - "conversions [Visual Basic], expression" ms.assetid: dd4b29e7-6fa1-428c-877e-69955420bb72 --- -# CType Function (Visual Basic) +# CType Operator (Visual Basic) Returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface. @@ -35,8 +35,8 @@ Any expression that is legal within an `As` clause in a `Dim` statement, that is > [!TIP] > You can also use the following functions to perform a type conversion: > -> - Type conversion functions such as `CByte`, `CDbl`, and `CInt` that perform a conversion to a specific data type. For more information, see [Type Conversion Functions](type-conversion-functions.md). -> - [DirectCast Operator](../operators/directcast-operator.md) or [TryCast Operator](../operators/trycast-operator.md). These operators require that one type inherit from or implement the other type. They can provide somewhat better performance than `CType` when converting to and from the `Object` data type. +> - Type conversion functions such as `CByte`, `CDbl`, and `CInt` that perform a conversion to a specific data type. For more information, see [Type Conversion Functions](../functions/type-conversion-functions.md). +> - [DirectCast Operator](directcast-operator.md) or [TryCast Operator](trycast-operator.md). These operators require that one type inherit from or implement the other type. They can provide somewhat better performance than `CType` when converting to and from the `Object` data type. `CType` is compiled inline, which means that the conversion code is part of the code that evaluates the expression. In some cases, the code runs faster because no procedures are called to perform the conversion. @@ -53,8 +53,8 @@ If the data type of `expression` or `typename` is a class or structure you've de |Keyword|Data types|Argument relationship|Run-time failure| |---|---|---|---| |`CType`|Any data types|Widening or narrowing conversion must be defined between the two data types|Throws | -|[DirectCast Operator](../operators/directcast-operator.md)|Any data types|One type must inherit from or implement the other type|Throws | -|[TryCast](../operators/trycast-operator.md)|Reference types only|One type must inherit from or implement the other type|Returns [Nothing](../nothing.md)| +|[DirectCast Operator](directcast-operator.md)|Any data types|One type must inherit from or implement the other type|Throws | +|[TryCast](trycast-operator.md)|Reference types only|One type must inherit from or implement the other type|Returns [Nothing](../nothing.md)| ## Overloading @@ -66,7 +66,7 @@ Type conversions of dynamic objects are performed by user-defined dynamic conver ## Example -The following example uses the `CType` function to convert an expression to the `Single` data type. +The following example uses the `CType` operator to convert an expression to the `Single` data type. [!code-vb[VbVbalrFunctions#24](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrFunctions/VB/Class1.vb#24)] @@ -76,8 +76,8 @@ For additional examples, see [Implicit and Explicit Conversions](../../programmi - - -- [Type Conversion Functions](type-conversion-functions.md) -- [Conversion Functions](conversion-functions.md) +- [Type Conversion Functions](../functions/type-conversion-functions.md) +- [Conversion Functions](../functions/conversion-functions.md) - [Operator Statement](../statements/operator-statement.md) - [How to: Define a Conversion Operator](../../programming-guide/language-features/procedures/how-to-define-a-conversion-operator.md) - [Type Conversion in the .NET Framework](../../../standard/base-types/type-conversion.md) diff --git a/docs/visual-basic/language-reference/operators/directcast-operator.md b/docs/visual-basic/language-reference/operators/directcast-operator.md index ceec73fa2dab5..c124c2b9fa667 100644 --- a/docs/visual-basic/language-reference/operators/directcast-operator.md +++ b/docs/visual-basic/language-reference/operators/directcast-operator.md @@ -17,7 +17,7 @@ Introduces a type conversion operation based on inheritance or implementation. `DirectCast` does not use the Visual Basic run-time helper routines for conversion, so it can provide somewhat better performance than `CType` when converting to and from data type `Object`. - You use the `DirectCast` keyword similar to the way you use the [CType Function](../functions/ctype-function.md) and the [TryCast Operator](trycast-operator.md) keyword. You supply an expression as the first argument and a type to convert it to as the second argument. `DirectCast` requires an inheritance or implementation relationship between the data types of the two arguments. This means that one type must inherit from or implement the other. + You use the `DirectCast` keyword similar to the way you use the [CType Operator](ctype-operator.md) and the [TryCast Operator](trycast-operator.md) keyword. You supply an expression as the first argument and a type to convert it to as the second argument. `DirectCast` requires an inheritance or implementation relationship between the data types of the two arguments. This means that one type must inherit from or implement the other. ## Errors and Failures @@ -29,7 +29,7 @@ Introduces a type conversion operation based on inheritance or implementation. |Keyword|Data types|Argument relationship|Run-time failure| |---|---|---|---| -|[CType Function](../functions/ctype-function.md)|Any data types|Widening or narrowing conversion must be defined between the two data types|Throws | +|[CType Operator](ctype-operator.md)|Any data types|Widening or narrowing conversion must be defined between the two data types|Throws | |`DirectCast`|Any data types|One type must inherit from or implement the other type|Throws | |[TryCast Operator](trycast-operator.md)|Reference types only|One type must inherit from or implement the other type|Returns [Nothing](../nothing.md)| diff --git a/docs/visual-basic/language-reference/operators/index.md b/docs/visual-basic/language-reference/operators/index.md index 569ff2df7fb4d..c3d7ff10af94c 100644 --- a/docs/visual-basic/language-reference/operators/index.md +++ b/docs/visual-basic/language-reference/operators/index.md @@ -13,6 +13,7 @@ ms.assetid: 3d3421df-fcc5-4888-9249-d78f16774ce6 - [Operator precedence in Visual Basic](operator-precedence.md) - [Operators listed by functionality](operators-listed-by-functionality.md) - [Data types of operator results](data-types-of-operator-results.md) +- [CType operator](ctype-operator.md) - [DirectCast operator](directcast-operator.md) - [TryCast operator](trycast-operator.md) - [NameOf operator](nameof.md) diff --git a/docs/visual-basic/language-reference/operators/trycast-operator.md b/docs/visual-basic/language-reference/operators/trycast-operator.md index d2811eb50b19e..68b2c2b22aa62 100644 --- a/docs/visual-basic/language-reference/operators/trycast-operator.md +++ b/docs/visual-basic/language-reference/operators/trycast-operator.md @@ -17,7 +17,7 @@ Introduces a type conversion operation that does not throw an exception. If an attempted conversion fails, `CType` and `DirectCast` both throw an error. This can adversely affect the performance of your application. `TryCast` returns [Nothing](../nothing.md), so that instead of having to handle a possible exception, you need only test the returned result against `Nothing`. - You use the `TryCast` keyword the same way you use the [CType Function](../functions/ctype-function.md) and the [DirectCast Operator](directcast-operator.md) keyword. You supply an expression as the first argument and a type to convert it to as the second argument. `TryCast` operates only on reference types, such as classes and interfaces. It requires an inheritance or implementation relationship between the two types. This means that one type must inherit from or implement the other. + You use the `TryCast` keyword the same way you use the [CType Operator](ctype-operator.md) and the [DirectCast Operator](directcast-operator.md) keyword. You supply an expression as the first argument and a type to convert it to as the second argument. `TryCast` operates only on reference types, such as classes and interfaces. It requires an inheritance or implementation relationship between the two types. This means that one type must inherit from or implement the other. ## Errors and Failures @@ -29,7 +29,7 @@ Introduces a type conversion operation that does not throw an exception. |Keyword|Data types|Argument relationship|Run-time failure| |---|---|---|---| -|[CType Function](../functions/ctype-function.md)|Any data types|Widening or narrowing conversion must be defined between the two data types|Throws | +|[CType Operator](ctype-operator.md)|Any data types|Widening or narrowing conversion must be defined between the two data types|Throws | |[DirectCast Operator](directcast-operator.md)|Any data types|One type must inherit from or implement the other type|Throws | |`TryCast`|Reference types only|One type must inherit from or implement the other type|Returns [Nothing](../nothing.md)| diff --git a/docs/visual-basic/misc/bc30423.md b/docs/visual-basic/misc/bc30423.md index 7abb461576fa8..9e480cdc5a651 100644 --- a/docs/visual-basic/misc/bc30423.md +++ b/docs/visual-basic/misc/bc30423.md @@ -24,4 +24,4 @@ Optional parameters cannot be of the data type of a structure. ## See also - [Structures and Classes](../programming-guide/language-features/data-types/structures-and-classes.md) -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) diff --git a/docs/visual-basic/misc/bc30512.md b/docs/visual-basic/misc/bc30512.md index 5e3e94fba5742..f0a891b3589bb 100644 --- a/docs/visual-basic/misc/bc30512.md +++ b/docs/visual-basic/misc/bc30512.md @@ -21,7 +21,7 @@ You have tried to convert a type to another type that may not be able to contain 1. Determine whether a conversion of any type exists from `` to ``. If both are Visual Basic elementary types, or if both are instances of classes, you can usually make this determination by consulting the table in [Widening and Narrowing Conversions](../programming-guide/language-features/data-types/widening-and-narrowing-conversions.md). -2. If only a narrowing conversion exists from `` to ``, you should use explicit casting. The [CType Function](../language-reference/functions/ctype-function.md) and [DirectCast Operator](../language-reference/operators/directcast-operator.md) keywords throw a run-time exception if the conversion fails. The [TryCast Operator](../language-reference/operators/trycast-operator.md) keyword applies only to reference types and returns [Nothing](../language-reference/nothing.md) if the conversion fails. +2. If only a narrowing conversion exists from `` to ``, you should use explicit casting. The [CType Function](../language-reference/operators/ctype-operator.md) and [DirectCast Operator](../language-reference/operators/directcast-operator.md) keywords throw a run-time exception if the conversion fails. The [TryCast Operator](../language-reference/operators/trycast-operator.md) keyword applies only to reference types and returns [Nothing](../language-reference/nothing.md) if the conversion fails. 3. If a narrowing conversion exists and your program can tolerate a run-time failure, or you are confident that a run-time failure is not possible, you can specify `Option Strict Off` at the beginning of your source code. But you should still enclose the conversion in a [Try...Catch...Finally Statement](../language-reference/statements/try-catch-finally-statement.md) block to avoid unexpected results or early termination of your program. @@ -35,7 +35,7 @@ You have tried to convert a type to another type that may not be able to contain - [Option Strict Statement](../language-reference/statements/option-strict-statement.md) - [Widening and Narrowing Conversions](../programming-guide/language-features/data-types/widening-and-narrowing-conversions.md) -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) - [DirectCast Operator](../language-reference/operators/directcast-operator.md) - [TryCast Operator](../language-reference/operators/trycast-operator.md) - [Nothing](../language-reference/nothing.md) diff --git a/docs/visual-basic/misc/bc30521.md b/docs/visual-basic/misc/bc30521.md index f4f14bead44f9..bb7a3259b5c3a 100644 --- a/docs/visual-basic/misc/bc30521.md +++ b/docs/visual-basic/misc/bc30521.md @@ -25,7 +25,7 @@ You have made a call to an overloaded method, but the compiler has found two or 1. Review all the overloads for the method and determine which one you want to call. -2. In your calling statement, make the data types of the arguments match the data types of the parameters defined for the desired overload. You might have to use the [CType Function](../language-reference/functions/ctype-function.md) to convert one or more data types to the defined types. +2. In your calling statement, make the data types of the arguments match the data types of the parameters defined for the desired overload. You might have to use the [CType Function](../language-reference/operators/ctype-operator.md) to convert one or more data types to the defined types. ## See also @@ -35,4 +35,4 @@ You have made a call to an overloaded method, but the compiler has found two or - [Overloads](../language-reference/modifiers/overloads.md) - [Overloaded Properties and Methods](../programming-guide/language-features/objects-and-classes/overloaded-properties-and-methods.md) - [Option Strict Statement](../language-reference/statements/option-strict-statement.md) -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) diff --git a/docs/visual-basic/misc/bc30741.md b/docs/visual-basic/misc/bc30741.md index 84e48dd8f0d67..0d94ef6fb83b4 100644 --- a/docs/visual-basic/misc/bc30741.md +++ b/docs/visual-basic/misc/bc30741.md @@ -21,4 +21,4 @@ A type conversion was attempted between two incompatible types. ## See also -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) diff --git a/docs/visual-basic/misc/bc30742.md b/docs/visual-basic/misc/bc30742.md index 6d5f5be36ddbd..3644d44f24b05 100644 --- a/docs/visual-basic/misc/bc30742.md +++ b/docs/visual-basic/misc/bc30742.md @@ -21,4 +21,4 @@ A type conversion was attempted between two incompatible types. ## See also -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) diff --git a/docs/visual-basic/misc/bc30753.md b/docs/visual-basic/misc/bc30753.md index 1383f27d4250f..630db156ccea0 100644 --- a/docs/visual-basic/misc/bc30753.md +++ b/docs/visual-basic/misc/bc30753.md @@ -19,11 +19,11 @@ ms.assetid: 7e1bb22e-a507-483e-bfd6-f3a43e24a232 ## To correct this error -- Explicitly convert collection objects by using one of the type conversion keywords. The [CType Function](../language-reference/functions/ctype-function.md) and [DirectCast Operator](../language-reference/operators/directcast-operator.md) keywords throw a run-time exception if the conversion fails. The [TryCast Operator](../language-reference/operators/trycast-operator.md) keyword returns [Nothing](../language-reference/nothing.md) if the conversion fails. +- Explicitly convert collection objects by using one of the type conversion keywords. The [CType Function](../language-reference/operators/ctype-operator.md) and [DirectCast Operator](../language-reference/operators/directcast-operator.md) keywords throw a run-time exception if the conversion fails. The [TryCast Operator](../language-reference/operators/trycast-operator.md) keyword returns [Nothing](../language-reference/nothing.md) if the conversion fails. ## See also -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) - [DirectCast Operator](../language-reference/operators/directcast-operator.md) - [TryCast Operator](../language-reference/operators/trycast-operator.md) - [Nothing](../language-reference/nothing.md) diff --git a/docs/visual-basic/misc/bc30792.md b/docs/visual-basic/misc/bc30792.md index fd195d4786918..160c3ac02efe3 100644 --- a/docs/visual-basic/misc/bc30792.md +++ b/docs/visual-basic/misc/bc30792.md @@ -25,5 +25,5 @@ The `TryCast` operator is used with a value type for at least one of the argumen - [TryCast Operator](../language-reference/operators/trycast-operator.md) - [DirectCast Operator](../language-reference/operators/directcast-operator.md) -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) - [Value Types and Reference Types](../programming-guide/language-features/data-types/value-types-and-reference-types.md) diff --git a/docs/visual-basic/misc/bc30793.md b/docs/visual-basic/misc/bc30793.md index 2b57a5d7eee98..1354a324b52a9 100644 --- a/docs/visual-basic/misc/bc30793.md +++ b/docs/visual-basic/misc/bc30793.md @@ -29,7 +29,7 @@ The [TryCast Operator](../language-reference/operators/trycast-operator.md) oper - If you need to pass this type parameter to `TryCast`, constrain it with one or more of the constraints in the preceding list. -- If you cannot require the type parameter to accept only a reference type, you cannot use it with `TryCast`. You might be able to use the [CType Function](../language-reference/functions/ctype-function.md) instead. +- If you cannot require the type parameter to accept only a reference type, you cannot use it with `TryCast`. You might be able to use the [CType Function](../language-reference/operators/ctype-operator.md) instead. ## See also diff --git a/docs/visual-basic/misc/bc30944.md b/docs/visual-basic/misc/bc30944.md index 71d0e9a7cc11d..a619661575a65 100644 --- a/docs/visual-basic/misc/bc30944.md +++ b/docs/visual-basic/misc/bc30944.md @@ -25,7 +25,7 @@ An expression uses the `CType` conversion function or the `DirectCast` or `TryCa ## See also -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) - [DirectCast Operator](../language-reference/operators/directcast-operator.md) - [TryCast Operator](../language-reference/operators/trycast-operator.md) - [Type Conversion Functions](../language-reference/functions/type-conversion-functions.md) diff --git a/docs/visual-basic/misc/bc33038.md b/docs/visual-basic/misc/bc33038.md index 6fa8d3b7ab922..a0c19e5b6c73a 100644 --- a/docs/visual-basic/misc/bc33038.md +++ b/docs/visual-basic/misc/bc33038.md @@ -44,4 +44,4 @@ A `For` loop specifies a counter variable of a type that does not support a requ - [Operator Statement](../language-reference/statements/operator-statement.md) - [How to: Define an Operator](../programming-guide/language-features/procedures/how-to-define-an-operator.md) - [How to: Define a Conversion Operator](../programming-guide/language-features/procedures/how-to-define-a-conversion-operator.md) -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) diff --git a/docs/visual-basic/misc/bc36621.md b/docs/visual-basic/misc/bc36621.md index 895bff180cdd6..e10113dcba248 100644 --- a/docs/visual-basic/misc/bc36621.md +++ b/docs/visual-basic/misc/bc36621.md @@ -23,7 +23,7 @@ An `Equals` operator in a `Join` or `Group Join` clause has attempted to compare ## See also -- [CType Function](../language-reference/functions/ctype-function.md) +- [CType Function](../language-reference/operators/ctype-operator.md) - [Type Conversions in Visual Basic](../programming-guide/language-features/data-types/type-conversions.md) - [Join Clause](../language-reference/queries/join-clause.md) - [Group Join Clause](../language-reference/queries/group-join-clause.md) diff --git a/docs/visual-basic/programming-guide/language-features/data-types/how-to-convert-an-object-to-another-type.md b/docs/visual-basic/programming-guide/language-features/data-types/how-to-convert-an-object-to-another-type.md index eb2da42edd93a..452dd478b996c 100644 --- a/docs/visual-basic/programming-guide/language-features/data-types/how-to-convert-an-object-to-another-type.md +++ b/docs/visual-basic/programming-guide/language-features/data-types/how-to-convert-an-object-to-another-type.md @@ -8,7 +8,7 @@ ms.assetid: 60cb5fc7-7ba4-4ab5-9c24-480fa12ddcdc --- # How to: Convert an Object to Another Type in Visual Basic -You convert an `Object` variable to another data type by using a conversion keyword such as [CType Function](../../../language-reference/functions/ctype-function.md). +You convert an `Object` variable to another data type by using a conversion keyword such as [CType Operator](../../../language-reference/operators/ctype-operator.md). ## Example diff --git a/docs/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions.md b/docs/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions.md index dc9f7fef51077..d955235483185 100644 --- a/docs/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions.md +++ b/docs/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions.md @@ -69,9 +69,9 @@ The following table shows the available conversion keywords. |`CULng`|[ULong Data Type](../../../language-reference/data-types/ulong-data-type.md)|Any numeric type (including `Byte`, `SByte`, and enumerated types), `Boolean`, `String`, `Object`| |`CUShort`|[UShort Data Type](../../../language-reference/data-types/ushort-data-type.md)|Any numeric type (including `Byte`, `SByte`, and enumerated types), `Boolean`, `String`, `Object`| -## The CType Function +## The CType Operator -The [CType Function](../../../language-reference/functions/ctype-function.md) operates on two arguments. The first is the expression to be converted, and the second is the destination data type or object class. Note that the first argument must be an expression, not a type. +The [CType Operator](../../../language-reference/operators/ctype-operator.md) operates on two arguments. The first is the expression to be converted, and the second is the destination data type or object class. Note that the first argument must be an expression, not a type. `CType` is an *inline function*, meaning the compiled code makes the conversion, often without generating a function call. This improves performance. diff --git a/docs/visual-basic/programming-guide/language-features/data-types/troubleshooting-data-types.md b/docs/visual-basic/programming-guide/language-features/data-types/troubleshooting-data-types.md index 34c8c699234cf..a2739e6d5315f 100644 --- a/docs/visual-basic/programming-guide/language-features/data-types/troubleshooting-data-types.md +++ b/docs/visual-basic/programming-guide/language-features/data-types/troubleshooting-data-types.md @@ -65,7 +65,7 @@ Note that it is not sufficient to declare `decimalRemainder` as `Decimal`. You m ## Boolean Type Does Not Convert to Numeric Type Accurately -[Boolean Data Type](../../../language-reference/data-types/boolean-data-type.md) values are not stored as numbers, and the stored values are not intended to be equivalent to numbers. For compatibility with earlier versions, Visual Basic provides conversion keywords ([CType Function](../../../language-reference/functions/ctype-function.md), `CBool`, `CInt`, and so on) to convert between `Boolean` and numeric types. However, other languages sometimes perform these conversions differently, as do the .NET Framework methods. +[Boolean Data Type](../../../language-reference/data-types/boolean-data-type.md) values are not stored as numbers, and the stored values are not intended to be equivalent to numbers. For compatibility with earlier versions, Visual Basic provides conversion keywords ([CType Operator](../../../language-reference/operators/ctype-operator.md), `CBool`, `CInt`, and so on) to convert between `Boolean` and numeric types. However, other languages sometimes perform these conversions differently, as do the .NET Framework methods. You should never write code that relies on equivalent numeric values for `True` and `False`. Whenever possible, you should restrict usage of `Boolean` variables to the logical values for which they are designed. If you must mix `Boolean` and numeric values, make sure that you understand the conversion method that you select. @@ -99,7 +99,7 @@ There is always a risk in using narrowing conversions, because they can fail at The [String Data Type](../../../language-reference/data-types/string-data-type.md) participates in very few widening conversions. `String` widens only to itself and `Object`, and only `Char` and `Char()` (a `Char` array) widen to `String`. This is because `String` variables and constants can contain values that other data types cannot contain. -When the type checking switch ([Option Strict Statement](../../../language-reference/statements/option-strict-statement.md)) is `On`, the compiler disallows all implicit narrowing conversions. This includes those involving `String`. Your code can still use conversion keywords such as `CStr` and [CType Function](../../../language-reference/functions/ctype-function.md), which direct the .NET Framework to attempt the conversion. +When the type checking switch ([Option Strict Statement](../../../language-reference/statements/option-strict-statement.md)) is `On`, the compiler disallows all implicit narrowing conversions. This includes those involving `String`. Your code can still use conversion keywords such as `CStr` and [CType Operator](../../../language-reference/operators/ctype-operator.md), which direct the .NET Framework to attempt the conversion. > [!NOTE] > The narrowing-conversion error is suppressed for conversions from the elements in a `For Each…Next` collection to the loop control variable. For more information and examples, see the "Narrowing Conversions" section in [For Each...Next Statement](../../../language-reference/statements/for-each-next-statement.md). diff --git a/docs/visual-basic/programming-guide/language-features/data-types/widening-and-narrowing-conversions.md b/docs/visual-basic/programming-guide/language-features/data-types/widening-and-narrowing-conversions.md index 788b621fe8677..e8223766a3ca9 100644 --- a/docs/visual-basic/programming-guide/language-features/data-types/widening-and-narrowing-conversions.md +++ b/docs/visual-basic/programming-guide/language-features/data-types/widening-and-narrowing-conversions.md @@ -93,7 +93,7 @@ An important consideration with a type conversion is whether the result of the c - — (integral types only) if the converted value is too large for the target type - If a class or structure defines a [CType Function](../../../language-reference/functions/ctype-function.md) to serve as a conversion operator to or from that class or structure, that `CType` can throw any exception it deems appropriate. In addition, that `CType` might call Visual Basic functions or .NET Framework methods, which in turn could throw a variety of exceptions. + If a class or structure defines a [CType Function](../../../language-reference/operators/ctype-operator.md) to serve as a conversion operator to or from that class or structure, that `CType` can throw any exception it deems appropriate. In addition, that `CType` might call Visual Basic functions or .NET Framework methods, which in turn could throw a variety of exceptions. ## Changes During Reference Type Conversions diff --git a/docs/visual-basic/programming-guide/language-features/procedures/how-to-call-an-operator-procedure.md b/docs/visual-basic/programming-guide/language-features/procedures/how-to-call-an-operator-procedure.md index 97ba2804d6ab2..8ea1a4045ec73 100644 --- a/docs/visual-basic/programming-guide/language-features/procedures/how-to-call-an-operator-procedure.md +++ b/docs/visual-basic/programming-guide/language-features/procedures/how-to-call-an-operator-procedure.md @@ -15,7 +15,7 @@ ms.assetid: 0dce42cc-f0b0-4c14-9f62-018b21f33497 --- # How to: Call an Operator Procedure (Visual Basic) -You call an operator procedure by using the operator symbol in an expression. In the case of a conversion operator, you call the [CType Function](../../../language-reference/functions/ctype-function.md) to convert a value from one data type to another. +You call an operator procedure by using the operator symbol in an expression. In the case of a conversion operator, you call the [CType Operator](../../../language-reference/operators/ctype-operator.md) to convert a value from one data type to another. You do not call operator procedures explicitly. You just use the operator, or the `CType` function, in an assignment statement or an expression, the same way you ordinarily use an operator. Visual Basic makes the call to the operator procedure. diff --git a/docs/visual-basic/programming-guide/language-features/procedures/how-to-define-a-conversion-operator.md b/docs/visual-basic/programming-guide/language-features/procedures/how-to-define-a-conversion-operator.md index 119cb2dbf7044..5537822877d69 100644 --- a/docs/visual-basic/programming-guide/language-features/procedures/how-to-define-a-conversion-operator.md +++ b/docs/visual-basic/programming-guide/language-features/procedures/how-to-define-a-conversion-operator.md @@ -15,7 +15,7 @@ ms.assetid: 54203dfa-c24b-463f-9942-d5153e89e762 If you have defined a class or structure, you can define a type conversion operator between the type of your class or structure and another data type (such as `Integer`, `Double`, or `String`). - Define the type conversion as a [CType Function](../../../language-reference/functions/ctype-function.md) procedure within the class or structure. All conversion procedures must be `Public Shared`, and each one must specify either [Widening](../../../language-reference/modifiers/widening.md) or [Narrowing](../../../language-reference/modifiers/narrowing.md). + Define the type conversion as a [CType Operator](../../../language-reference/operators/ctype-operator.md) procedure within the class or structure. All conversion procedures must be `Public Shared`, and each one must specify either [Widening](../../../language-reference/modifiers/widening.md) or [Narrowing](../../../language-reference/modifiers/narrowing.md). Defining an operator on a class or structure is also called *overloading* the operator. diff --git a/docs/visual-basic/programming-guide/language-features/procedures/how-to-use-a-class-that-defines-operators.md b/docs/visual-basic/programming-guide/language-features/procedures/how-to-use-a-class-that-defines-operators.md index a861dce1f1810..c35f452a53437 100644 --- a/docs/visual-basic/programming-guide/language-features/procedures/how-to-use-a-class-that-defines-operators.md +++ b/docs/visual-basic/programming-guide/language-features/procedures/how-to-use-a-class-that-defines-operators.md @@ -21,13 +21,13 @@ If you are using a class or structure that defines its own operators, you can ac ## Example - The following example accesses the SQL structure , which defines the conversion operators ([CType Function](../../../language-reference/functions/ctype-function.md)) in both directions between a SQL string and a Visual Basic string. Use `CType(`*SQL string expression*, `String)` to convert a SQL string to a Visual Basic string, and `CType(`*Visual Basic string expression*, `)` to convert in the other direction. + The following example accesses the SQL structure , which defines the conversion operators ([CType Function](../../../language-reference/operators/ctype-operator.md)) in both directions between a SQL string and a Visual Basic string. Use `CType(`*SQL string expression*, `String)` to convert a SQL string to a Visual Basic string, and `CType(`*Visual Basic string expression*, `)` to convert in the other direction. [!code-vb[VbVbcnProcedures#30](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbcnProcedures/VB/Class1.vb#30)] [!code-vb[VbVbcnProcedures#31](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbcnProcedures/VB/Class1.vb#31)] - The structure defines a conversion operator ([CType Function](../../../language-reference/functions/ctype-function.md)) from `String` to and another from to `String`. The statement that assigns `title` to `jobTitle` makes use of the first operator, and the function call uses the second. + The structure defines a conversion operator ([CType Function](../../../language-reference/operators/ctype-operator.md)) from `String` to and another from to `String`. The statement that assigns `title` to `jobTitle` makes use of the first operator, and the function call uses the second. ## Compile the code diff --git a/docs/visual-basic/programming-guide/language-features/procedures/operator-procedures.md b/docs/visual-basic/programming-guide/language-features/procedures/operator-procedures.md index 2f1a69c602cee..0c83baa695359 100644 --- a/docs/visual-basic/programming-guide/language-features/procedures/operator-procedures.md +++ b/docs/visual-basic/programming-guide/language-features/procedures/operator-procedures.md @@ -51,7 +51,7 @@ Public Shared [Widening | Narrowing] Operator operatorsymbol ( operand1 [, oper End Operator ``` -You use the `Widening` or `Narrowing` keyword only on a type conversion operator. The operator symbol is always [CType Function](../../../language-reference/functions/ctype-function.md) for a type conversion operator. +You use the `Widening` or `Narrowing` keyword only on a type conversion operator. The operator symbol is always [CType Operator](../../../language-reference/operators/ctype-operator.md) for a type conversion operator. You declare two operands to define a binary operator, and you declare one operand to define a unary operator, including a type conversion operator. All operands must be declared `ByVal`. diff --git a/docs/visual-basic/programming-guide/language-features/procedures/troubleshooting-procedures.md b/docs/visual-basic/programming-guide/language-features/procedures/troubleshooting-procedures.md index 52bab3a4b1add..7089eb75cc01e 100644 --- a/docs/visual-basic/programming-guide/language-features/procedures/troubleshooting-procedures.md +++ b/docs/visual-basic/programming-guide/language-features/procedures/troubleshooting-procedures.md @@ -77,7 +77,7 @@ The following items, even though they pertain to the parameter list, are not com You cannot overload a procedure by varying only one or more of the preceding items. -**Correct approach:** To be able to define a procedure overload, you must vary the signature. Because you must use the same name, you must vary the number, order, or data types of the parameters. In a generic procedure, you can vary the number of type parameters. In a conversion operator ([CType Function](../../../language-reference/functions/ctype-function.md)), you can vary the return type. +**Correct approach:** To be able to define a procedure overload, you must vary the signature. Because you must use the same name, you must vary the number, order, or data types of the parameters. In a generic procedure, you can vary the number of type parameters. In a conversion operator ([CType Operator](../../../language-reference/operators/ctype-operator.md)), you can vary the return type. ### Overload resolution with Optional and ParamArray arguments @@ -93,7 +93,7 @@ When you have determined which overload you want to call, be careful to observe - Ideally, your arguments should have the exact same data types as the corresponding parameters. In any case, the data type of each argument must widen to that of its corresponding parameter. This is true even with the [Option Strict Statement](../../../language-reference/statements/option-strict-statement.md) set to `Off`. If an overload requires any narrowing conversion from your argument list, that overload is not eligible to be called. - If you supply arguments that require widening, make their data types as close as possible to the corresponding parameter data types. If two or more overloads accept your argument data types, the compiler resolves your call to the overload that calls for the least amount of widening. -You can reduce the chance of data type mismatches by using the [CType Function](../../../language-reference/functions/ctype-function.md) conversion keyword when preparing your arguments. +You can reduce the chance of data type mismatches by using the [CType Function](../../../language-reference/operators/ctype-operator.md) conversion keyword when preparing your arguments. ### Overload resolution failure @@ -109,7 +109,7 @@ In the first call, the compiler eliminates the first overload because the type o In the second call, the compiler cannot eliminate any of the overloads on the basis of narrowing. It eliminates the third overload for the same reason as in the first call, because it can call the second overload with less widening of the argument types. However, the compiler cannot resolve between the first and second overloads. Each has one defined parameter type that widens to the corresponding type in the other (`Byte` to `Short`, but `Single` to `Double`). The compiler therefore generates an overload resolution error. -**Correct approach:** To be able to call an overloaded procedure without ambiguity, use [CType Function](../../../language-reference/functions/ctype-function.md) to match the argument data types to the parameter types. The following example shows a call to `z` that forces resolution to the second overload. +**Correct approach:** To be able to call an overloaded procedure without ambiguity, use [CType Function](../../../language-reference/operators/ctype-operator.md) to match the argument data types to the parameter types. The following example shows a call to `z` that forces resolution to the second overload. [!code-vb[VbVbcnProcedures#65](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbcnProcedures/VB/Class1.vb#65)] diff --git a/docs/visual-basic/toc.yml b/docs/visual-basic/toc.yml index bf1aec59d6a19..fd922fb986657 100644 --- a/docs/visual-basic/toc.yml +++ b/docs/visual-basic/toc.yml @@ -368,8 +368,6 @@ items: items: - name: Return Values for the CStr Function href: language-reference/functions/return-values-for-the-cstr-function.md - - name: CType Function - href: language-reference/functions/ctype-function.md - name: Modifiers href: language-reference/modifiers/index.md items: @@ -589,6 +587,8 @@ items: href: language-reference/operators/andalso-operator.md - name: Await Operator href: language-reference/operators/await-operator.md + - name: CType Operator + href: language-reference/operators/ctype-operator.md - name: DirectCast Operator href: language-reference/operators/directcast-operator.md - name: Function Expression