|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Convert VB <-> C# Utility
Hi All,
Here is a very usefull link for all of you guys out there to convert your VB code to C#, and visa versa. I am finding it very usefull while converting myself to a C# rookie after 4,5 happy years in the VB.Net corner ![]() Sure everyone will make use of it some stage or another. Convert VB to C# Jo. ![]()
__________________
Fitness & Diet resources Career Descriptions Boat Cruises All code that is posted by me has not been tested, and it should only be interpreted as a guideline to a solution. There is no guarantee that any of my code samples will work as provided, and should be customized to suite the required need. Last edited by D.O.M.I.N.A.T.O.R : June 2nd, 2006 at 11:34 AM. |
|
#2
|
|||
|
|||
|
I have it bookmarked, dunno when I'll have the chance to put it to use as I have just started dipping my toe into the mighty world of VB.Net.
![]() |
|
#3
|
||||
|
||||
|
only problem is it doesn't do "efficient" conversion.
It takes this Code:
((int)strValue); and converts it to this Code:
CType(strValue, Integer) for efficient conversion it should convert it to this Code:
DirectCast(strValue, Integer) as DirectCast does conversion many times faster than CType, which is present for backwards compatibility only. |
|
#4
|
||||
|
||||
|
Quote:
Use DirectCast if you're absolutely positively sure that an object is the specified type and the run-time type of the expression are the same. If you're not sure but expect that the conversion will work, use CType. The run-time performance of DirectCast is better than that of CType. However, DirectCast throws an InvalidCastException error if the argument types do not match, so you must be sure. DirectCast only operates on reference types, not value types. |
|
#5
|
||||
|
||||
|
For reference types you should use DirectCast if you are sure the object can be cast as another object. If not use CType.
For value types instead of using CType you should use the Convert class (Convert.ToInt16(strValue). |
![]() |
| Viewing: ASP Free Forums > Other > ASP Free Lounge > Convert VB <-> C# |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|