In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will share with you what operators are related to VB.NET type conversion. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
VB.NET type conversion provides two transformation operators: DirectCast and CType
DirectCast is * because it usually produces more efficient code and better preserves type safety. However, DirectCast can only be used to convert a reference type to another type, while the CType operator can be used to convert a reference type or value type to another type.
Using the CType operator to convert a primitive type to a primitive type is very useful and common, so VB.NET provides some transformation operators specifically for this purpose:
CBool: converts an object to a Boolean
CByte: converts an object to a Byte
CChar converts an object to Char
CDate converts an object to DateTime
CDbl converts an object to Double
CDec converts an object to Decimal
CInt converts an object to Int32
CLng converts an object to Int64
CObj converts an object to Object
CShort converts an object to Int16
CSng converts an object to Single
CStr converts an object to String
If DirectCast and CType and the above convenient transformation operator cannot find a way to convert the specified object to the desired type, an InvalidCastException exception will be thrown.
Type of test object
Because the DirectCast and CType operators attempt to convert an object from one type to another. If the transformation is not compatible, an InvalidCastException exception will be thrown, and in order for the program to recover from the exception, the developer must take advantage of the exception handling mechanism. If we want to avoid using exception handling code, we can use TypeOf....Is expressions to check whether the object is compatible with the specified type. The result is a Boolean value.
Example:
TypeOf TEST Is Object
Where TEST is the reference to be checked and the type specified by Object
Thank you for reading! This is the end of this article on "what are the operators related to VB.NET type conversion?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.