Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp3
- {
- public class MyLib
- {
- static public string[] keywords = {
- "abstract", "as", "base", "bool", "break",
- "byte", "case", "catch", "char", "checked",
- "class", "const", "continue", "decimal", "default",
- "delegate", "do", "double", "else", "enum",
- "event", "explicit", "extern", "false", "finally",
- "fixed", "float", "for", "foreach", "goto",
- "if", "implicit", "in", "int", "interface",
- "internal", "is", "lock", "long", "namespace",
- "new", "null", "object", "operator", "out",
- "override", "params", "private", "protected", "public",
- "readonly", "ref", "return", "sbyte", "sealed",
- "short", "sizeof", "stackalloc", "static", "string",
- "struct", "switch", "this", "throw", "true",
- "try", "typeof", "uint", "ulong", "unchecked",
- "unsafe", "ushort", "using", "virtual", "void",
- "volatile", "while" }; // string[ ]
- } // class MyLib
- // Слова по алфавиту - нумеруемая коллекция, пригодная для LINQ:
- public class Words : IEnumerable<string[]>
- {
- string[] source; // Ссылка на исходный массив «слов»
- public Words(string[] source)
- { // Конструктор
- this.source = source;
- }
- public System.Collections.Generic.IEnumerator<string[]>
- GetEnumerator()
- {
- string letters = "abcdefghijklmnopqrstuvwxyz";
- for (int i = 0; i < letters.Length; i++)
- {
- string[] resAr = (from word in source
- where letters[i] == word[0]
- select word).ToArray();
- yield return resAr;
- }
- } // GetEnumerator<>
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- { yield return "Заглушка!!!"; }
- } // class Words
- class Program
- {
- static void Main()
- {
- string[] test = { "one", "two", "three", "four", "five", "zero" };
- Words words = new Words(test);
- Console.WriteLine(words.Count());
- Console.WriteLine("Названия цифр по алфавиту:");
- foreach (var item in words)
- foreach (var el in item)
- Console.Write(el + " ");
- Console.WriteLine();
- //.. Выберем из поcледовательности массив слов на букву 'f':
- var res = from s in words
- where s.Length > 0 && s[0][0] == 'f'
- select s;
- Console.WriteLine("Названия цифр на букву 'f':");
- foreach (var item in res)
- foreach (var el in item)
- Console.WriteLine(el);
- // Создадим объект, представляющий массивы ключевых слов:
- Words keys = new Words(MyLib.keywords);
- // Выберем из поcледовательности массив слов на букву 'i':
- var set = keys.Where(s => s.Length > 0 && s[0][0] == 'i');
- /*var set = from s in keys
- where s.Length > 0 && s[0][0] == 'i'
- select s;*/
- Console.WriteLine("Служебные слова на букву 'i':");
- foreach (var item in set)
- foreach (var el in item)
- Console.WriteLine(el);
- Console.WriteLine( set.ToArray<string[]>()[0].Length);
- } // Main
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement