int num;
int.TryParse("5",out num, 10);
Which will do the same as TryParse, but addtional if the parsing fails, the out parameter will get the defualt value 10
Can I implement it?
With extension methods I can implement the following:
int num;
num.TryParse("5",out num, 10);
But this look different than the rest of the TryParse methods..
You cannot add static methods to existing classes, but you can add your own static method to your own class, for example:
public static class MyConversions
{
public static bool TryParse(string value, out int num, int defaultValue)
{
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With