I have a program that needs to test to see if a string can be converted to a double but has no use for the converted double value.
I could create my own TryParse method in my own NameSpace, but shouldn’t I be able to add an overloaded form of the function in the same namespace that has no output param?
namespace System
{
using System;
/// <summary>
/// TODO: Update summary.
/// </summary>
public class Double
{
public bool TryParse(string value)
{
double outDouble;
return Double.TryParse(value, out outDouble);
}
}
}
I get this error:
Error 1 No overload for method 'TryParse' takes 2 arguments
because my class is hiding the real Double class.
Update:
Same error with this:
namespace System
{
/// <summary>
/// TODO: Update summary.
/// </summary>
public static class Double
{
public static bool TryParse(string value)
{
double outDouble;
return global::System.Double.TryParse(value, out outDouble);
}
}
}
The problem here is that you are hiding the
System.Doubletype with your ownSystem.Double. This means that when you try to callSystem.Double.TryParse, the compiler is looking at your class and that’s the error being reported.You need to either change your namespaces or class names.