FAQ - VB to C sharp net guide

Question
Convert a string to an integer, date, numeric type
Answer

VB(6) has isnumeric and isdate functions.

VB.net and c#.net are both more precise in their nature.

Each relevant data type has a TryParse method:

in c#

int iResult;

string sTest;

int.TryParse(sTest, out iResult)

and similarly for date, guid, single, double etc

This is a definite improvement on VB6 as the conversion process can be implimented in one line and the conversion criteria are more precise. Also a default value can be ascribed if the parse function fails. My only argument is trying to find this fuctionality when searching for terms like inumeric, cast and convert.

Further info

http://msdn.microsoft.com/en-us/library/f02979c7.aspx - int32
http://msdn.microsoft.com/en-us/library/9h21f14e.aspx - date
http://msdn.microsoft.com/en-us/library/system.guid.tryparse.aspx - guid
http://msdn.microsoft.com/en-us/library/system.single.tryparse.aspx -single
etc

 

If you found this information useful, please share it!


This FAQ was last updated on 31 August 2011

Contact Information

To find out more about Ava solutions you can contact us in a number of ways:
Follow Us...