Hello:
I'm starting a solution with Visual Studio .NET 2005 Beta 1 one of its
projects (the bussines logic) must use only the standar types/members of a
CLI Standard Library implementation, because it's intended to be compiled on
any implementation of the Common Language Infrastructure, not only on the
.NET Framework.
The problem is that I don't know if I can use the TryParse methods of the
base types, since there is not even a working draft of the CLI 3 Standar (but
I've seen one of the C# 2 Standar).
Will the TryParse methods be standarized? I think they should, in fact, I
think that if you had to choose between standarizing Parse or TryParse, it
would be better to remove Parse and only standarize TryParse. If you want to
implement a Parse method you could always do this:
public int Parse(string s)
{
int result;
if (!int.TryParse(s, out result))
throw new FormatException("The specified string is not a valid
number.");
return result;
}
But figure out you only want to check if a string has a valid numeric
format, and you can only use Parse because TryParse is not standarized: this
case you have to catch an exception:
public bool IsValidInt32(string s)
{
try { int.Parse(s); }
catch (FormatException) { return false; }
return true;
}
And you know it's not a recommended programming technique to expect and
catch exceptions for value-checking purposes.
In conclusion: I would appreciate if some guy of the BCL team at Microsoft
could tell me if TryParse will be in the standard, and if not, I suggest it.
And also I would like to know how long will the new version of the standard
take to be released.
Thank you very much in advance, and sorry for my bad english, it's not my
native language.
Again, thank you.
Samuel.