using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Laba07 { public class MyClass { public string K; public int Res = 0; public double K1; //метод 1 public static void Method1(MyClass C) { //Длина строки while (true) { Console.WriteLine("Введите длину слова:"); C.K = Console.ReadLine(); Console.Clear(); if (Int32.TryParse(C.K, out C.Res) == false) { if (double.TryParse(C.K, out C.K1) == true) Console.WriteLine("Введено дробное число!"); else { if (C.K == "") Console.WriteLine("Введена пустая строка!"); else Console.WriteLine("Введена строка!"); } } else break; } //Имя файла while (true) { C.K1 = 1; Console.WriteLine("Введите имя файла:"); C.K = Console.ReadLine(); Console.Clear(); if (C.K == "") { Console.WriteLine("Введена пустая строка!"); continue; C.K1 = 0; } if (File.Exists(C.K) == false) { Console.WriteLine("Введено неверное имя файла!"); C.K1 = 0; } if (C.K1 != 0) break; } } //метод 2 public void Method2() { int count = 0, words = 0; string text = System.IO.File.ReadAllText(this.K); for (int i = 0; i < text.Length;i++) { if (text[i] != ' ') { count++; } else { if (count == Res) words++; count = 0; }; } Console.WriteLine("Количество слов длиной {0} символов в файле {1} составляет {2} штук.", Res, K, words); } } class Program { static void Main(string[] args) { MyClass MC = new MyClass(); MyClass.Method1(MC); MC.Method2(); Console.ReadKey(); } } }