Beispiel #1
0
        public static FileAnalizeResult AnalizeFile(string filePath)
        {
            string[] lines = GetFileContent(filePath);

            var result = new FileAnalizeResult
            {
                BrokenLines = new List <string>()
            };

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    double sum = lines[i].Split(",").Sum(l => Double.Parse(l, CultureInfo.InvariantCulture));
                    if (sum > result.MaxSum)
                    {
                        result.MaxSum        = sum;
                        result.MaxLineNumber = i + 1;
                    }
                }
                catch
                {
                    result.BrokenLines.Add(lines[i]);
                }
            }

            return(result);
        }
        public static void Main(string[] args)
        {
            string filePath;

            if (args.Length > 0)
            {
                filePath = args[0];
            }
            else
            {
                Console.WriteLine("Enter file path: ");
                filePath = Console.ReadLine();
            }

            FileAnalizeResult result = Helper.AnalizeFile(filePath);

            Console.WriteLine("Max sum: " + result.MaxSum);
            Console.WriteLine("Line number: " + result.MaxLineNumber);
            Console.WriteLine("Broken lines:");
            foreach (var line in result.BrokenLines)
            {
                Console.WriteLine(line);
            }
        }