And if so, why can't you do this:
public interface IParsable
{
static IParsable Parse(string s);
static bool TryParse(string s, out IParsable);
}
in c #?
EDIT: Or, alternatively:
public interface IParseable<T>
{
static T Parse(string s);
static bool TryParse(string s, out T);
}
EDIT No. 2: I found out the stupidity of my paths by trying to use IParsable, as suggested by many below. The following example. Of course, there is no way to allow the TryParse call ...
public IParsable ReadFromKeyboard()
{
IParsable ToReturn;
bool FirstTry = false;
bool Success;
do
{
if (!FirstTry)
DisplayError();
AskForInput();
Success = IParsable.TryParse(Console.ReadLine, out ToReturn);
FirstTry = false;
} while(!Success)
return ToReturn;
}
source
share