Ok so you found http://www.developerfusion.com/tools/convert/vb-to-csharp/ and now you are a c# programer as well...
Except that there are a few things this does not handle and honsetly you also need to write new code. On of the things the above site does not do is handle conversion of database types that can include null values and common or garden ints, longs etc.
So how to we check that (sql) int is not null?
If you google this you will probably get a dozen (smart arse) answers to the effect that an int is is not null by definition. Of course you know that, I know that. What we want to know is can we get the vb equivalent of is numeric?
Well we can import the VB namespace and use the VB command, but that is really not so cool. Why? Well there a better solution. IsNumeric just tells us if the string can be intepreted as a number. What we are idealy looking for is, is it in range?
We have TryParse as in:
Int16.TryParse(txtEmailPort.Text.Trim(), out iPort);
Its defined as:
public static bool TryParse( string s, out int result)
(or in vb terms)
Public Shared Function TryParse ( s As String, _
<OutAttribute> ByRef result As Integer _
) As Boolean
Examples can be found here:
http://msdn.microsoft.com/en-us/library/f02979c7%28v=VS.90%29.aspx
There are int32 and the other varieties you'd expect. the int is passed by reference and it returns a (boolean) value to say it did not find an exception.
Happy c# programming!
|
© 2009 Added Value Applications
|