public static Complex Parse(string s)
{
var r = new Regex(@"\((?<real>.*),(?<imaginary>.*)\)", RegexOptions.None);
Match m = r.Match(s);
if (m.Success)
{
return new Complex(
double.Parse(m.Result("${real}")),
double.Parse(m.Result("${imaginary}"))
);
}
else
{
throw new FormatException("String representation of the complex number is not correctly formatted.");
}
}