VB.NET中的转换和数据类型转换

Casting is the process of converting one data type to another, for example, from an Integer type to a String type. Some operations in VB.NET require specific data types to work. Casting creates the type you need. The first article in this two-part series, Casting and Data Type Conversions in VB.NET, introduces casting. This article describes the three operators you can use to cast in VB.NET - DirectCast, CType and TryCast - and compares their performance.

强制转换是将一种数据类型转换为另一种数据类型的过程 ,例如,从整数类型转换为字符串类型。 VB.NET中的某些操作需要特定的数据类型才能工作。 转换会创建您需要的类型。 这个由两部分组成的系列文章的第一篇文章VB.NET中的转换和数据类型转换介绍了转换。 本文介绍了可用于在VB.NET中进行转换的三个运算符-DirectCast,CType和TryCast-并比较了它们的性能。

Performance is one of the big differences between the three casting operators according to Microsoft and other articles. For example, Microsoft is usually careful to warn that, "DirectCast ... can provide somewhat better performance than CType when converting to and from data type Object." (Emphasis added.)

根据Microsoft和其他文章,性能是这三个铸造运营商之间的最大差异之一。 例如,Microsoft通常会小心警告:“ 在与数据类型Object进行相互转换时 ,DirectCast ...可以提供比CType更好的性能。” (强调)。

I decided to write some code to check.

我决定编写一些代码进行检查。

But first a word of caution. Dan Appleman, one of the founders of the technical book publisher Apress and a reliable technical guru, once told me that benchmarking performance is much harder to do correctly than most people realize. There are factors like machine performance, other processes that might be running in parallel, optimization like memory caching or compiler optimization, and errors in your assumptions about what the code is actually doing. In these benchmarks, I have tried to eliminate "apples and oranges" comparison errors and all tests have been run with the release build. But there still might be errors in these results. If you notice any, please let me know.

但是首先要提请注意。 丹·阿普尔曼(Dan Appl

你可能感兴趣的:(字符串,python,java,编程语言,人工智能)