Jump to content

TypeCasting (string) vs ToString


DooVoo

Recommended Posts

I am currently writing some code that extracts some string data from a DataRow and wondered which of the following two statements are the best practise and why:

string myVar = (string)(MyRow["MyItem"]);

string myVar = MyRow["MyItem"].ToString();

Answers on a postcard please :)

Link to comment
Share on other sites

Okay, after some checking and reading I've found the following.Using the method ToString() will work with all classes that include it without any side effects of potential class "wierdness". The main downside is that it is slower that type-casting.However, having said that, the difference in speed is barely worth mentioning and so I conclude that using ToString() is the way forward!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...