Beispiel #1
0
        static void Main(string[] args)
        {
            Programmer          programmer = new Programmer("Скуби");
            ProgrammingLanguage p          = new ProgrammingLanguage("JS", 4.5f, "Add", "Del", "Rename");
            ProgrammingLanguage c          = new ProgrammingLanguage("C#", 7.0f, "Add", "Del");

            Console.WriteLine(p.ToString());
            p.GetOperation();
            Console.WriteLine(c.ToString());
            c.GetOperation();
            //c.NewOpt = p.NewOpt = "Concat";
            programmer.NewProperty += p.AddOperation;
            //programmer.NewProperty += c.AddOperation;
            //p.DelOpt = "Del";
            programmer.NewProperty += p.DeleteOptions;
            programmer.Rename      += p.NewVersion;
            //programmer.CommandAddOperation();
            //programmer.CommandRenOperation();
            //p.NewOpt = "Range";
            //c.NewOpt = "District";
            programmer.NewProperty -= p.DeleteOptions;
            //programmer.CommandAddOperation();
            Console.WriteLine(p.ToString());
            p.GetOperation();
            Console.WriteLine(c.ToString());
            c.GetOperation();

            //------------------------------
            string str = "dne/ir*f @y#m ,";

            string forExampleStr = "Abrarkadabra";

            Console.WriteLine(StringFunction.OperationString(forExampleStr, x => x.Replace("bra", String.Empty)));


            Console.WriteLine($"Строка до: {str}");
            str = StringFunction.AddStr(str, "?dlr_ow_)_(     ^o_l_l)eh");
            Console.WriteLine($"После: {str}\n");

            Console.WriteLine($"Строка до: {str}");
            StringFunction.StringFun delStrFun = StringFunction.RemoveSymbol;
            delStrFun += StringFunction.Reverse;
            delStrFun += StringFunction.ToUpperFirstLetters;
            delStrFun += StringFunction.RemoveSpace;
            delStrFun(ref str);
            Console.WriteLine($"После: {str}\n");

            //Console.WriteLine($"Строка до: {str}");
            //str = StringFunction.RemoveSymbol(str);
            //Console.WriteLine($"После: {str}\n");

            //Console.WriteLine($"Строка до: {str}");
            //str = StringFunction.Reverse(str);
            //Console.WriteLine($"После: {str}\n");

            //Console.WriteLine($"Строка до: {str}");
            //str = StringFunction.ToUpperFirstLetters(str);
            //Console.WriteLine($"После: {str}\n");

            //Console.WriteLine($"Строка до: {str}");
            //str = StringFunction.RemoveSpace(str);
            //Console.WriteLine($"После: {str}\n");

            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Programmer p1 = new Programmer("Серёга");

            //создать некоторое количество объектов (языков программирования)
            ProgrammingLanguage Lang1 = new ProgrammingLanguage("JS", 4.5f, "Add", "Del", "Rename");
            ProgrammingLanguage Lang2 = new ProgrammingLanguage("C#", 7.0f, "Add", "Del");

            Console.WriteLine(Lang1);
            Console.WriteLine(Lang2);

            p1.NewProperty += Lang1.Add;        //подписываем объект на событие
            p1.NewProperty += Lang1.Add;
            p1.NewProperty += Lang1.Add;

            p1.NewProperty += Lang2.Delete;
            p1.NewProperty += Lang2.Delete;

            p1.Rename      += Lang1.Rename_L;
            p1.NewProperty -= Lang1.Add;

            Lang2.NewVersion(3.1);

            Lang2.AddOperation("Input");
            Lang1.DeleteOptions("Add");

            p1.CommandAddOperation();

            Console.WriteLine(Lang1);
            Console.WriteLine(Lang2);

            Func <string, string> work1; //обобщенный делегат, второй параметр - возврат
            Action <string>       work2; //не возвр значений
            Func <string, string> work3;
            Func <string, string> work4;
            Func <string, string> work5;

            work1 = str1 =>
            {
                char[] sign = { '.', ',', '!', '?', '-', ':' };
                for (int i = 0; i < str1.Length; i++)
                {
                    if (sign.Contains(str1[i]))
                    {
                        str1 = str1.Remove(i, 1);
                    }
                }
                Console.WriteLine(str1);
                return(str1);
            };
            work2 = delegate(string str2)    //анонимный метод
            {
                str2 += " World";
                Console.WriteLine(str2);
            };
            work3 = str3 =>
            {
                str3 = str3.Replace(" ", string.Empty);
                Console.WriteLine(str3);
                return(str3);
            };
            work4 = str4 =>
            {
                str4 = str4.ToUpper();
                Console.WriteLine(str4);
                return(str4);
            };
            work5 = str5 =>
            {
                str5 = str5.ToLower();
                Console.WriteLine(str5);
                return(str5);
            };

            string str = "Hel?lo!";

            Console.WriteLine("Строка в начале: " + str);
            Console.WriteLine("Строки в конце: ");
            string s1, s2, s3;

            s1 = StringJob.RemoveSimbols(str, work1);
            StringJob.AddText(s1, work2);
            s2 = StringJob.RemoveSpase(s1, work3);
            s3 = StringJob.Upper(s2, work4);
            StringJob.Lower(s3, work5);
        }