tailieunhanh - Visual Basic .NET The Complete Reference phần 3

Mức độ khớp nối phương pháp khác nhau trong bốn lựa chọn quan trọng để cung cấp các dữ liệu để phương pháp. Mức cao nhất của các khớp nối giữa các phương thức kết quả từ cấp lớp hoặc các biến toàn cầu, trong khi mức thấp nhất của các khớp nối là đạt được | Working with Variables and Constants CastTarget Expression CastTarget CBool CByte CChar CDate CDec CDbl CInt CLng CObj CShort CSng CStr Table 4-15 Classic VB Conversion Functions and Framework Conversion Methods Classic Function Conversion Class Return Type CBool ToBoolean Boolean CByte ToByte Byte CChar ToChar Char CDate ToDateTime DateTime CDbl ToDouble Double CDec ToDecimal Decimal CInt ToInteger Integer CLng ToLong Long CObj ToObject Object CShort ToShort Short CSng ToSingle Single CStr ToString String CType ChangeType Object Here are more examples of code using the cast functions and the conversion methods Dim myNumber As Integer 0 Dim booHoo As Boolean CBool myNumber booHoo False is written to the console in the above example by the way the default value of Integer is 0 . Depending on your application s target platform it might be safer to use the Convert class s methods instead of the classic Visual Basic cast functions or any other cast functions wrapped for .NET usage . Your code will also be more palatable to other .NET languages like C . On the other hand there might be a tradeoff in performance because the call to one of Convert s methods is not necessarily faster than the classic cast function. In addition to the Convert class methods listed in Table 4-16 are a number of additional framework type-handling methods that are also accessible from the Convert class such as ChangeType and ISDBNull. Working with Variables and Constants In the average life of an application it is not uncommon for example to find a similar expression to the following in an application Private discount As Integer Private total amount As Double . . . discount 10 120 Working with Variables and Constants amount Compute the discount percent total amount discount 100 This little algorithm computes two types of numbersIntegers and Doubles. As you know an Integer is a data type that represents a whole number an Double on the other hand represents .

TỪ KHÓA LIÊN QUAN