DooVoo Posted January 23, 2006 Share Posted January 23, 2006 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 More sharing options...
DooVoo Posted January 25, 2006 Author Share Posted January 25, 2006 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 More sharing options...
aspnetguy Posted January 27, 2006 Share Posted January 27, 2006 ToString() is the standard way. Link to comment Share on other sites More sharing options...
DooVoo Posted January 27, 2006 Author Share Posted January 27, 2006 Typecasting is faster though, if you know there wont be any strange results that is. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now