Beispiel #1
0
        static void Main(string[] args)
        {
            //екземплярна версія
            Sort   sort   = new Sort("!@*&^#$$$.//");
            StrMod strmod = sort.Sorting;

            strmod();
            //статична версія
            Sort.StrMod1 strMod1 = Sort.Sortingg;
            char[]       str1    = "4asdf6546".ToCharArray();
            strMod1(str1);

            //черга на основі масиву
            Queue <int> queue = new Queue <int>(3);

            queue.Overflow += mes => Console.WriteLine(mes);
            try
            {
                queue.Enqueue(1);
                queue.Enqueue(2);

                queue.Enqueue(3);
                queue.Dequeue();
                queue.Enqueue(4);
                queue.Enqueue(5);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Console.WriteLine("Hello World!");

            StrMod strOp;
            StrMod replaceSp  = ReplaceSpaces;
            StrMod removeSp   = Removespace;
            StrMod reverseStr = reverse;
            string str        = "This is test";

            strOp  = ReplaceSpaces;
            strOp += reverseStr;

            strOp(ref str);
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();

            strOp -= replaceSp;
            strOp += removeSp;

            str = "This is test";

            strOp(ref str);
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //Сконструировать делегаты
            StrMod strOp;
            StrMod replaceSp  = ReplaceSpaces;
            StrMod removeSp   = RemoveSpaces;
            StrMod reverseStr = Reverse;
            string str        = "Это простой тесg т";

            //организовать групповую переадресацию
            strOp  = replaceSp;
            strOp += reverseStr;


            //Обратиться к делегату с групповой адресацией
            strOp(ref str);
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            //Удалить метод замены пробелов и добавить метод удаления пробелов
            strOp -= replaceSp;
            strOp += removeSp;
            str    = "Это простой тест"; //восстановить исходную строку

            //Обратиться к делегату с групповой адресацией
            strOp(ref str);
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //StrMod strOp = new StrMod(ReplaceSpaces);
            //string str;

            //str = strOp("This is test");
            //Console.WriteLine("Resulting string: " +str);
            //Console.WriteLine();

            //strOp =new StrMod(Removespace);
            //str = strOp("This is test");
            //Console.WriteLine("Resulting string: " + str);
            //Console.WriteLine();

            //strOp = new StrMod(reverse);
            //str = strOp("This is test");
            //Console.WriteLine("Resulting string: " + str);

            StrMod strOp = ReplaceSpaces;
            string str;

            str = strOp("This is test");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();

            strOp = Removespace;
            str   = strOp("This is test");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();

            strOp = reverse;
            str   = strOp("This is test");
            Console.WriteLine("Resulting string: " + str);
        }
        static void Main(string[] args)
        {
            StringOps so = new StringOps(); // создать экземпляр

            // объекта класса StringOps
            // Инициализировать делегат.
            StrMod strOp = so.ReplaceSpaces;
            string str;

            // Вызвать методы с помощью делегатов.
            str = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);

            Console.WriteLine();

            strOp = so.RemoveSpaces;
            str   = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);

            Console.WriteLine();

            strOp = so.Reverse;
            str   = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);

            Console.ReadKey();
        }
Beispiel #6
0
        public void DelegatePracticeMethodGroupConversion()
        {
            // Construct a delegate using method group conversion.
            StrMod strOp = DelegateTest.ReplaceSpaces; // use method group conversion
            string str;

            // Call methods through the delegate.
            str = strOp("This is a test.");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();
            strOp = DelegateTest.RemoveSpaces; // use method group conversion
            str   = strOp("This is a test.");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();
            strOp = DelegateTest.Reverse; // use method group conversion
            str   = strOp("This is a test.");
            Console.WriteLine("Resulting string: " + str);
            // Calling Intance Class
            Console.WriteLine("Delegate  Method Group Conversion with Intance Method");
            DelegateTest DlgOb = new DelegateTest();

            strOp = DlgOb.ReplaceSpacesInsTanceMethod;
            str   = strOp("My name is Muhammad Adshikuzzaman");

            Console.CursorSize = 10;
            Console.WriteLine("My space replaced name is : " + str);
            Console.WriteLine();
        }
    static void Main()
    {
        // Construct delegates.
        StrMod strOp;
        StrMod replaceSp  = ReplaceSpaces;
        StrMod removeSp   = RemoveSpaces;
        StrMod reverseStr = Reverse;
        string str        = "This is a test";

        // Set up multicast.
        strOp  = replaceSp;
        strOp += reverseStr;

        // Call multicast.
        strOp(ref str);
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();

        // Remove replace and add remove.
        strOp -= replaceSp;
        strOp += removeSp;
        str    = "This is a test."; // reset string

        // Call multicast.
        strOp(ref str);
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
    }
Beispiel #8
0
        public static void ExecuteExample()
        {
            //previous version 2.0
            StrMod strOp = new StrMod(removeSpaces);

            //new using the inference
            strOp = removeNewLines;
        }
        static void Main()
        {
            // Создать делегаты, ссылающиеся на лямбда- выражения,
            // выполняющие различные операции с символьными строками.

            // Заменить пробелы дефисами
            StrMod ReplaceSpaces = s =>
            {
                Console.WriteLine("Замена пробелов дефисами.");
                return(s.Replace(" ", "-"));
            };

            // Удалить пробелы.
            StrMod RemoveSpaces = s =>
            {
                string temp = "";
                int    i;
                Console.WriteLine("Удаление пробелов.");
                for (i = 0; i < s.Length; i++)
                {
                    if (s[i] != ' ')
                    {
                        temp += s[i];
                    }
                }
                return(temp);
            };

            // Обратить строку.
            StrMod Reverse = s =>
            {
                string temp = "";
                int    i, j;
                Console.WriteLine("Обращение строки.");
                for (j = 0, i = s.Length - 1; i >= 0; i--, j++)
                {
                    temp += s[i];
                }
                return(temp);
            };

            string str;
            // Обратиться к лямбда-выражениям с помощью делегатов.
            StrMod strOp = ReplaceSpaces;

            str = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = RemoveSpaces;
            str   = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = Reverse;
            str   = strOp("Это простой тест.");
            Console.WriteLine("Результирующа строка: " + str);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            //создать делегаты, ссылающиеся на лямбда выражения, выполняющие различные операции с символьными строками

            //заменить пробелы дефисами
            StrMod ReplaceSpaces = s =>
            {
                Console.WriteLine("Замена пробелов дефисами");
                return(s.Replace(' ', '-'));
            };

            //удалить пробелы
            StrMod RemoveSpaces = s =>
            {
                string temp = "";
                int    i;
                Console.WriteLine("Удаление пробелов");
                for (i = 0; i < s.Length; i++)
                {
                    if (s[i] != ' ')
                    {
                        temp += s[i];
                    }
                }
                return(temp);
            };

            //обратить строку
            StrMod Reverse = s => {
                string temp = "";
                int    i;
                Console.WriteLine("Обращение строки");
                for (i = s.Length - 1; i >= 0; i--)
                {
                    temp += s[i];
                }
                return(temp);
            };

            string str;

            //обратиться к лямбда-выражениям с помощью делегатов
            StrMod strOp = ReplaceSpaces;

            str = strOp("Это простой тест");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = RemoveSpaces;
            str   = strOp("Это простой тест");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = Reverse;
            str   = strOp("Это простой тест");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();
        }
        static void ShowResult(StrMod modifier)
        {
            var testText = "Это просто текст";

            modifier(ref testText);

            Message(testText);
            Message();
        }
Beispiel #12
0
        public static List <string> StringFormater(this List <string> text, StrMod strMod)
        {
            for (int i = 0; i < text.Count; i++)
            {
                text[i] = strMod(text[i]);
            }

            return(text);
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            StrMod obj = Reverse;
            string s   = obj("Reversing a string");

            Console.WriteLine(s);
            obj = ReplaceSpaceWithHypens;
            s   = obj("Replace space with hypens");
            Console.WriteLine(s);
            Console.ReadKey();
        }
Beispiel #14
0
    static void Main()
    {
        // Create delegates that refer to lambda expressions
        // that perform various string modifications.
        // Replaces spaces with hyphens.
        StrMod ReplaceSpaces = s =>
        {
            Console.WriteLine("Replacing spaces with hyphens.");
            return(s.Replace(' ', '-'));
        };
        // Remove spaces.
        StrMod RemoveSpaces = s =>
        {
            string temp = "";
            int    i;
            Console.WriteLine("Removing spaces.");
            for (i = 0; i < s.Length; i++)
            {
                if (s[i] != ' ')
                {
                    temp += s[i];
                }
            }
            return(temp);
        };
        // Reverse a string.
        StrMod Reverse = s =>
        {
            string temp = "";
            int    i, j;
            Console.WriteLine("Reversing string.");
            for (j = 0, i = s.Length - 1; i >= 0; i--, j++)
            {
                temp += s[i];
            }
            return(temp);
        };
        string str;
        // Call methods through the delegate.
        StrMod strOp = ReplaceSpaces;

        str = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
        strOp = RemoveSpaces;
        str   = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
        strOp = Reverse;
        str   = strOp("This is a test.");

        Console.WriteLine("Resulting string: " + str);
    }
Beispiel #15
0
    static void Main()
    {
        StrMod strOp = ReplaceSpaces;
        string str;

        str = strOp("This is a test.");
        Console.WriteLine(str);

        strOp = RemoveSpace;
        str   = strOp("This is a test.");
        Console.WriteLine(str);
    }
Beispiel #16
0
    public static void Main()
    {
        StrMod strOp = new StrMod(replaceSpaces);
        string str;

        str = strOp("This is a test.");

        strOp = new StrMod(removeSpaces);
        str   = strOp("This is a test.");

        strOp = new StrMod(reverse);
        str   = strOp("This is a test.");
    }
Beispiel #17
0
        static void Main()
        {
            // Create delegates that refer to lambda expressions
            // that perform various string modifications.
            // Replaces spaces with hyphens.
            StrMod ReplaceSpaces = s =>
            {
                Console.WriteLine("Replacing spaces with hyphens.");
                return(s.Replace(' ', '-'));
            };
            string str = ReplaceSpaces("This is to demonstrate use of statement lambdas");

            Console.WriteLine(str);
        }// end Main
Beispiel #18
0
    public static void Main()
    {
        // Initialize a delegate.
        StrMod strOp = new StrMod(StringOps.replaceSpaces);
        string str;

        // Call methods through delegates.
        str = strOp("This is a test.");

        strOp = new StrMod(StringOps.removeSpaces);
        str   = strOp("This is a test.");

        strOp = new StrMod(StringOps.reverse);
        str   = strOp("This is a test.");
    }
Beispiel #19
0
    public static void Main()
    {
        StrMod strOp = replaceSpaces; // use method group conversion
        string str;

        // Call methods through the delegate.
        str = strOp("This is a test.");


        strOp = removeSpaces; // use method group conversion
        str   = strOp("This is a test.");


        strOp = reverse; // use method group converison
        str   = strOp("This is a test.");
    }
Beispiel #20
0
        public void DelegatePracticeWithInstanceMthod()
        {
            // Construct a delegate.
            StrMod strOp = new StrMod(DelegateTest.ReplaceSpaces);
            string str;
            // Calling Intance Class

            DelegateTest DlgOb = new DelegateTest();

            strOp = new StrMod(DlgOb.ReplaceSpacesInsTanceMethod);
            str   = strOp("My name is Muhammad Adshikuzzaman");

            Console.CursorSize = 10;
            Console.WriteLine("My space replaced name is : " + str);
            Console.WriteLine();
        }
Beispiel #21
0
        public static void delegateMultitasking()
        {
            StrMod chain;
            StrMod a   = try_delegate.ReplaceSpaces;
            StrMod b   = try_delegate.reverseSTring;
            string str = "this is a test";

            chain = a + b;
            //chain -= b;

            str = chain(str);

            //str = a(str);
            //str = b(str);

            Console.WriteLine(str);
        }
Beispiel #22
0
    public Chapter1()
    {
        var delegObj = new DelegateTest();
        string str;

        var strOp = new StrMod(delegObj.ReplaceSpaces);
        str = strOp("Test string line");
        Console.WriteLine("str: " + str + "\n");

        strOp = delegObj.RemoveSpace;
        str = strOp("Test string line");
        Console.WriteLine("str: " + str + "\n");

        strOp = delegObj.Reverse;
        str = strOp("Test string line");
        Console.WriteLine("str: " + str + "\n");
    }
Beispiel #23
0
    public static void Main()
    {
// Construct a delegate.
        StrMod strOp = new StrMod(ReplaceSpaces);
        string str;

// Call methods through the delegate.
        str = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
        strOp = new StrMod(RemoveSpaces);
        str   = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
        strOp = new StrMod(Reverse);
        str   = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
    }
    //static void Main()
    //{
    //    // Construct a delegate.
    //    StrMod strOp = new StrMod(ReplaceSpaces);
    //    string str;

    //    // Call methods through the delegate.
    //    str = strOp("This is a test.");
    //    Console.WriteLine("Resulting string: " + str);
    //    Console.WriteLine();
    //    strOp = new StrMod(RemoveSpaces);
    //    str = strOp("This is a test.");
    //    Console.WriteLine("Resulting string: " + str);
    //    Console.WriteLine();
    //    strOp = new StrMod(Reverse);
    //    str = strOp("This is a test.");
    //    Console.WriteLine("Resulting string: " + str);
    //}

    static void Main()
    {
        // Construct a delegate using method group conversion.
        StrMod strOp = ReplaceSpaces; // use method group conversion
        string str;

        // Call methods through the delegate.
        str = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
        strOp = RemoveSpaces; // use method group conversion
        str   = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
        strOp = Reverse; // use method group conversion
        str   = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
    }
Beispiel #25
0
        static void Main(string[] args)
        {
            StringOp so    = new StringOp();
            StrMod   strOp = so.ReplaceSpaces;
            string   str;

            str = strOp("This is test");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();

            strOp = so.Removespace;
            str   = strOp("This is test");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();

            strOp = so.reverse;
            str   = strOp("This is test");
            Console.WriteLine("Resulting string: " + str);
        }
Beispiel #26
0
        //}

        //class Program
        //{
        static void Main(string[] args)
        {
            // Сконструировать делегат.
            StrMod strOp = new StrMod(ReplaceSpaces);
            string str;

            // Вызвать методы с помощью делегата.
            str = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();
            strOp = new StrMod(RemoveSpaces);
            str   = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();
            strOp = new StrMod(Reverse);
            str   = strOp("Это простой тест.");
            Console.WriteLine("Результирующая строка: " + str);
            Console.ReadKey();
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            //сконструировать делегат, используя групповое преобразование методов
            StrMod strOp = ReplaceSpaces;
            String str   = strOp("Это простой тест");

            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = RemoveSpaces;
            str   = strOp("Это простой тест");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = Reverse;
            str   = strOp("Это простой тест");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            StringOps so    = new StringOps();           //создаём экземпляр
            StrMod    strOp = so.ReplaceSpaces;          // инициализируем делегат
            String    str   = strOp("Это простой тест"); //вызываем методы с помощью делегата

            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = so.RemoveSpaces;
            str   = strOp("Это простой тест");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();

            strOp = so.Reverse;
            str   = strOp("Это простой тест");
            Console.WriteLine("Результирующая строка: " + str);
            Console.WriteLine();
        }
Beispiel #29
0
    static void Main()
    {
        StrMod strOp = ReplaceSpace;
        string str;

        str = strOp("This is a test");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();

        strOp = RemoveSpace;
        str   = strOp("This is a test");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();

        strOp = Reverse;
        str   = strOp("This is a test");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
    }
        static void Main(string[] args)
        {
            StrMod strOP = new StrMod(DelegateTest.ReplaceSpaces);
            string str;

            str = strOP("This is a test.");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();

            strOP = new StrMod(DelegateTest.RemoveSpace);
            str   = strOP("This is a test.");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();

            strOP = new StrMod(DelegateTest.Reverse);
            str   = strOP("This is a test.");
            Console.WriteLine("Resulting string: " + str);
            Console.WriteLine();
            Console.ReadKey();
        }
    static void Main()
    {
        StringOps so = new StringOps(); // create an instance of StringOps
        // Initialize a delegate.
        StrMod strOp = so.ReplaceSpaces;
        string str;

        // Call methods through delegates.
        str = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();

        strOp = so.RemoveSpaces;
        str   = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
        Console.WriteLine();
        strOp = so.Reverse;
        str   = strOp("This is a test.");
        Console.WriteLine("Resulting string: " + str);
    }