Convert.Toxx vs DataType.Parse  
Author Message
kymaita





PostPosted: .NET Base Class Library, Convert.Toxx vs DataType.Parse Top

Whats is the best practice between using

Convert.ToInt16 ("stringVar")

short.Parse("stringVar")

what is more aproppiate for performance and memory space use

thnks




.NET Development23  
 
 
Lepaca





PostPosted: .NET Base Class Library, Convert.Toxx vs DataType.Parse Top

 

Convert.ToInt16("string")  calls Short.Parse("string")


 
 
Peter Ritchie





PostPosted: .NET Base Class Library, Convert.Toxx vs DataType.Parse Top

Convert.ToInt16(String) simply performs a null check and calls short.Parse(String, IFormatProvider) with CultureInfo.CurrentCulture as the IFormatProvider argument.

Convert.ToInt16(String) will not let you override the culture of the current thread; if you may need to do that I recommend using short.Prase(String, IFormatProvider) directly.



 
 
kymaita





PostPosted: .NET Base Class Library, Convert.Toxx vs DataType.Parse Top

Ok thnks guys so I can assume that short.parse in more faster in the case I dont use any aditional parameter.

ky