private static void Main(string[] args) { TextScanner s = null; double sum = 0; try { s = new TextScanner(new StreamReader("usnumbers.txt")); s.UseCulture(new CultureInfo("en-US")); while (s.HasNext()) { if (s.HasNextDouble()) { sum += s.NextDouble(); } else { s.Next(); } } } finally { if (s != null) { s.Close(); } } Console.WriteLine(sum); }
public void CanTranslateIndividualTokens() { double sum = 0; using (var s = new TextScanner(new StreamReader("usnumbers.txt"))) { s.UseCulture(new CultureInfo("en-US")); int count = 0; while (s.HasNext()) { if (s.HasNextDouble()) { sum += s.NextDouble(); } else { s.Next(); } Assert.That(count++ < 100); } } Assert.That(sum, Is.EqualTo(1032778.74159)); }
private static void Main(string[] args) { TextScanner s = null; double sum = 0; try { s = new TextScanner(new StreamReader("usnumbers.txt")); s.UseCulture(new CultureInfo("en-US")); while (s.HasNext()) { if (s.HasNextDouble()) { sum += s.NextDouble(); } else { s.Next(); } } } finally { if (s != null) { s.Close(); } } Console.WriteLine(sum); }