private string GetCycleCount(CountDelegate func)
        {
            string inp = fReader.ReadLine();

            int[]         block    = ParseMas(inp);
            List <string> stepList = new List <string>
            {
                string.Join(" ", block)
            };

            while (stepList.Where(x => x.Equals(stepList[stepList.Count - 1])).ToList().Count < 2)
            {
                int num = block.Max();
                int i   = Array.IndexOf(block, num);
                block[i] = 0;
                while (num > 0)
                {
                    i = i < block.Length - 1 ? ++i : 0;
                    block[i]++;
                    num--;
                }
                stepList.Add(string.Join(" ", block));
            }
            fReader.BaseStream.Position = 0;
            return(func(stepList).ToString());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            StringHelper helper  = new StringHelper();
            Student      student = new Student();

            CountDelegate delegate1 = helper.GetCount;
            CountDelegate delegate2 = helper.GetCountSymbolA;

            //CountDelegate error = helper.GetCountSymbol;

            string testString = "LAMPa";

            Console.WriteLine($"Общее количество символов {TestDelegate(delegate1, testString)}");
            Console.WriteLine($"Общее количество символов {helper.GetCount(testString)}");
            Console.WriteLine($"Общее количество символов A {TestDelegate(delegate2, testString)}");
            Console.WriteLine($"Общее количество символов A {helper.GetCountSymbolA(testString)}");
            //ShowMessage method = Show;
            //Action<string> method = Show;
            //student.Moving = Show;
            //student.Move(10, method);

            student.Moving += Student_Moving;
            //student.Moving += student_Moving;
            student.Move(10);
        }
        private string GetCount(CountDelegate func)
        {
            int inp = ParseNum(fReader.ReadLine());

            fReader.BaseStream.Position = 0;
            return(func(inp).ToString());
        }
Exemple #4
0
        public static void ShowDelegate()
        {
            //Передаем ссылку на метод при создании экзмепляра делегата
            CountDelegate countDelegate = new CountDelegate(Discount);

            //Вызываем метод на который указывает делегат
            countDelegate.Invoke();
        }
        public static void ShowNonStaticDelegate()
        {
            MethodsForDelegate methodsForDelegate = new MethodsForDelegate();

            CountDelegate countDelegate = methodsForDelegate.Count;

            countDelegate();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            StringHelper helper = new StringHelper();

            Console.WriteLine("-- Пример 01 -------");

            CountDelegate del01 = helper.GetCount;
            CountDelegate del02 = helper.GetCountSumbolA;

            // ошибочное объявление делегата из-за неподходящей сигнатуры
            // CountDelegate del03 = helper.GetCountSymbol;

            string testString = "CAPACITY";

            Console.WriteLine($"Общее количество символов = {del01(testString)}");
            Console.WriteLine($"Количество символов A = {del02(testString)}");
            Console.WriteLine("---------");
            Console.WriteLine($"Общее количество символов = {TestDelegate(del01, testString)}");
            Console.WriteLine($"Количество символов A = {TestDelegate(del02, testString)}");
            Console.WriteLine("---------");

            Console.WriteLine("-- Пример 02 -------");
            Student student = new Student();

            student.Move01(1);
            Console.WriteLine("---------");

            ShowMessage method = Show;

            student.Move02(2, method);

            // использование обобщенных делегатов
            Console.WriteLine("-- Пример 03 -------");
            Action <string> methodForExample03 = Show;

            student.Move03(3, methodForExample03);

            // использование поля класса в качестве хранения делегата - псевдособытие
            Console.WriteLine("-- Пример 04 -------");
            student.Moving = Show;
            student.Move04(4);

            // использование События
            Console.WriteLine("-- Пример 05 -------");
            student.MovingEvent += Student_MovingEvent;
            student.Move05(5);

            // Ping-Pong
            Console.WriteLine("-- Самостоятельная работа: Ping-Pong");
            Ping ping = new Ping();
            Pong pong = new Pong(ping);

            ping.Subscribe(pong);
            ping.Innings();

            // delay
            Console.ReadKey();
        }
Exemple #7
0
 internal static void Bind()
 {
     _closeDelegate = Library.GetProcAddress <CloseDelegate>("mdbx_cursor_close") as CloseDelegate;
     _openDelegate  = Library.GetProcAddress <OpenDelegate>("mdbx_cursor_open") as OpenDelegate;
     _getDelegate   = Library.GetProcAddress <GetDelegate>("mdbx_cursor_get") as GetDelegate;
     _putDelegate   = Library.GetProcAddress <PutDelegate>("mdbx_cursor_put") as PutDelegate;
     _delDelegate   = Library.GetProcAddress <DelDelegate>("mdbx_cursor_del") as DelDelegate;
     _countDelegate = Library.GetProcAddress <CountDelegate>("mdbx_cursor_count") as CountDelegate;
 }
 private string GetCount(CountDelegate func)
 {
     int result = 0;
     List<int> instructList = ParseInstruction();
     int i = 0;
     while (i < instructList.Count && i >= 0)
     {
         int temp = i;
         (i, instructList[temp]) = func(i, instructList[i]);
Exemple #9
0
 public SuperCounter()
 {
     algorithm = delegate(int limit){
         for (int i = 0; i <= limit; i++)
         {
             Console.Write(i + " ");
         }
         Console.WriteLine("\n");
     };
 }
Exemple #10
0
 public SuperCounter()
 {
     algoritm = delegate(int limit)
     {
         for (int i = 0; i < limit; i++)
         {
             Console.Write(i + "  ");
         }
     };
 }
        public Dictionary <string, object> GetComputedTags(TemplateMetadata metadata, Dictionary <string, object> tagValues)
        {
            var result = new Dictionary <string, object>();

            if (metadata.ComputedTags != null)
            {
                var interpreter = new Interpreter();
                foreach (var tag in tagValues)
                {
                    interpreter.SetVariable(tag.Key, tag.Value);
                }

                CountDelegate     countFunc     = Count;
                TransformDelegate xmlEncodeFunc = XmlEncode;
                TransformDelegate lowerCaseFunc = LowerCase;
                TransformDelegate upperCaseFunc = UpperCase;
                TransformDelegate titleCaseFunc = TitleCase;
                TransformDelegate kebabCaseFunc = KebabCase;
                interpreter.SetFunction("Count", countFunc);
                interpreter.SetFunction("count", countFunc);
                interpreter.SetFunction("xmlEncode", xmlEncodeFunc);
                interpreter.SetFunction("lowerCase", lowerCaseFunc);
                interpreter.SetFunction("lowerCaseInvariant", lowerCaseFunc);
                interpreter.SetFunction("upperCase", upperCaseFunc);
                interpreter.SetFunction("upperCaseInvariant", upperCaseFunc);
                interpreter.SetFunction("titleCase", titleCaseFunc);
                interpreter.SetFunction("kebabCase", kebabCaseFunc);

                foreach (var computedTag in metadata.ComputedTags)
                {
                    try
                    {
                        if (!result.ContainsKey(computedTag.Key))
                        {
                            object value         = interpreter.Eval(computedTag.Expression);
                            object computedValue = value is bool?((bool)value) == true : value;
                            result.Add(computedTag.Key, computedValue);
                            if (!tagValues.ContainsKey(computedTag.Key))
                            {
                                interpreter.SetVariable(computedTag.Key, computedValue);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var error = $"Cannot compute `{computedTag.Key}` expression `{computedTag.Expression}: {ex}`";
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(error);
                        Console.ResetColor();
                    }
                }
            }

            return(result);
        }
Exemple #12
0
        static void Main(string[] args)
        {
            StringHelper helper = new StringHelper();

            CountDelegate d1 = helper.GetCount;        //у метода GetCount - схожая сигнатура с делегатом, приравниваем ссылку на метод в делегат (связываем метод и делегат)
            CountDelegate d2 = helper.GetCountSymbolA; //у метода GetCountSymbolA - схожая сигнатура с делегатом, приравниваем ссылку на метод в делегат (связываем метод и делегат)

            string testString = "LAMP";

            Console.WriteLine($"Общее количество символов {TestDelegate(d1, testString)}"); //с помощью вспомогатеьлной фунции проверяем работу первого делегата d1 и связанной с ним функции
            Console.WriteLine($"Количество символов А: {TestDelegate(d2, testString)}");    //с помощью вспомогательно функции проверяем работу второго делегата
        }
Exemple #13
0
        static void Main(string[] args)
        {
            CountDelegate countDelegate = Factorial;

            countDelegate += Fibanachi;
            countDelegate += Step_2;

            //SuperCounter superCounter = new SuperCounter();
            //superCounter.Calculate(150);

            SuperCounter superCounter = new SuperCounter(countDelegate);

            superCounter.Calculate(150);
        }
Exemple #14
0
        static void Main(string[] args)
        {
            StringHelper helper = new StringHelper();

            CountDelegate d1 = helper.GetCount;
            CountDelegate d2 = helper.GetCountSymbolA;

            //CountDelegate error = helper.GetCountSymbol; //Нельзя использовать, т.к. дилегат имеет отличную сигнатуру int(string,char)

            string testString = "LAMP";

            Console.WriteLine("Общее количество симаолов: {0}", TestDelegate(d1, testString));
            Console.WriteLine("Количество символов А: {0}", TestDelegate(d2, testString));

            Console.ReadLine();
        }
Exemple #15
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");


            StringHelper helper = new StringHelper();

            CountDelegate delegate1 = helper.GetCount;
            CountDelegate delegate2 = helper.GetCountSymbolA;

            string testingString = "LAMP";

            Console.WriteLine(TestDelegate(delegate1, testingString));
            Console.WriteLine(TestDelegate(delegate2, testingString));

            Console.ReadLine();
        }
Exemple #16
0
        internal static bool TryCount <T, TSize, TInput>(TInput begin, TInput end, out TSize count)
            where TInput : struct, IInputIterator <T, TSize, TInput>
            where TSize : struct, IConvertible
        {
            CountDelegate <T, TSize, TInput> countImpl = begin.GetProperty <CountDelegate <T, TSize, TInput> >();

            if (countImpl != null)
            {
                count = countImpl(begin, end);
                return(true);
            }
            else
            {
                count = SizeOperations <TSize> .Default.From(-1);

                return(false);
            }
        }
Exemple #17
0
        public static bool Validate(string[] arr, CountDelegate d)
        {
            int sum = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                sum = 0;
                for (int j = 0; j < arr [i].Length; j++)
                {
                    sum += (int)arr [i] [j];
                }
                if (sum != d(arr, i))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #18
0
        static void Main(string[] args)
        {
            Student student = new Student();

            student.Mooving += Student_Mooving;
            student.Moove(7);

            #region StringHelper

            StringHelper  helper = new StringHelper();
            CountDelegate d1     = helper.GetCount;
            CountDelegate d2     = helper.GetCountSymbolA;

            string testString = "LAMPA";

            Console.WriteLine(testString);
            Console.WriteLine($"Общее количество символов: {TestDelegate(d1, testString)}");
            Console.WriteLine($"Количство символов А: {TestDelegate(d2, testString)}");

            #endregion

            Console.ReadKey();
        }
Exemple #19
0
 public void setCountDelegate(CountDelegate count)
 {
     GetCount = count;
 }
Exemple #20
0
 public PagerModel2(CountDelegate count)
     : this()
 {
     GetCount = count;
 }
Exemple #21
0
 static int TestDelegate(CountDelegate method, string testString)
 {
     return(method(testString));
 }
Exemple #22
0
 public static void ExecuteDelegate(CountDelegate countDelegate)
 {
     countDelegate.Invoke();
 }
Exemple #23
0
 private void BtnFileCountRowsClick(object sender, EventArgs e)
 {
     txtFileRows.Text = "Calculating...";
     var invoker = new CountDelegate(FileHandler.CountRows);
     invoker.BeginInvoke(EndCountRows, invoker);
 }
        public IAsyncResult BeginCount(AsyncCallback callback, object state)
        {
            CountDelegate countDelegate = Count;

            return(countDelegate.BeginInvoke(callback, state));
        }
Exemple #25
0
 public void setCountDelegate(CountDelegate count)
 {
     GetCount = new CountDelegate(count);
 }
Exemple #26
0
 public void Set_algoritm(CountDelegate algo)
 {
     algoritm += algo;
 }
Exemple #27
0
 public SuperCounter(CountDelegate algo)
 {
     algoritm = algo;
 }
Exemple #28
0
 static int TestDelegate(CountDelegate method, string str)
 {
     return(method(str));
 }
Exemple #29
0
        static void Main(string[] args)
        {
            var list = new GenericList <string>();     //сконструированный тип

            string a;

            Console.Write("Добавить ");
            a = Console.ReadLine();

            list.Added += new ShowMess(ColorDisplay);   //подписка

            list.Add(a);
            list.Added -= ColorDisplay;      //otpiska
            list.Add("Первый");
            list.Add("Второй");
            list.Added    += ColorDisplay;
            list.Withdraw += ColorDisplay;

            CountDelegate    d1 = list.GetCount;
            CountDelegateAll d2 = list.GetAllCount;

            Console.WriteLine($"Добавить {a}, Первый, Второй");
            Console.WriteLine("Всего строк: " + list.Count);
            Console.WriteLine("Элементы: " + list[0] + " " + list[1] + " " + list[2]);
            Console.WriteLine("Кол-во символов в 1й строке: {0}", TestDelegate(d1, list[0]));
            Console.WriteLine("All sumbals in Stack: {0}", TestDelegate2(d2, list));
            Console.WriteLine(ListNode <int> .GetID());


            Console.WriteLine("\n\rУдалить первый элемент");
            list.RemoveAt(0);
            Console.WriteLine(list.Count);
            Console.WriteLine("Элементы: " + list[0] + " " + list[1]);

            Console.WriteLine("\nДобавить 1 в начало списка");
            list.InsertAt("1", 0);
            Console.WriteLine("Всего строк: " + list.Count);
            Console.WriteLine("Элементы: " + list[0] + " " + list[1] + " " + list[2]);

            Console.WriteLine("\nВставить Audi в позицию 2");
            list.InsertAt("Audi", 2);
            Console.WriteLine("Всего строк: " + list.Count);
            Console.WriteLine("Элементы: " + list[0] + " " + list[1] + " " + list[2] + " " + list[3]);


            Console.WriteLine("\nУдалить первый элемент");
            list.Remove(list[0]);
            Console.WriteLine("Всего строк: " + list.Count);
            Console.WriteLine("Элементы: " + list[0] + " " + list[1] + " " + list[2]);

            Console.WriteLine();



            Console.WriteLine("СТРОКИ. \n Для выполнения операции нажмите соответствующий № и Enter \n 1-Добавить \n 2-Удалить \n 3-Вставить на место N \n 4-Количество \n 5-Показать \n 6-Поиск по ID");
            Console.WriteLine(" Exit - для выхода из программы");

            string f = "*111*";

            while (f != "Exit")
            {
                string b;
                f = Console.ReadLine();

                switch (f)
                {
                case "Exit":
                {
                    Thread.Sleep(1500);
                    //Environment.Exit(0);
                    break;
                }

                case "1":
                {
                    Console.WriteLine("Введите новую строку: ");
                    b = Console.ReadLine();
                    list.Add(b);
                    break;
                };

                case "2":
                {
                    Console.WriteLine("Введите строку, которую нужно удалить (учитывайте регистр):");
                    b = Console.ReadLine();
                    list.Remove(b);
                    break;
                }

                case "3":
                {
                    Console.WriteLine("Введите сперва строку, а затем место, куда её вставить:");
                    b = Console.ReadLine();
                    int c = Convert.ToInt16(Console.ReadLine()) - 1;
                    list.InsertAt(b, c);
                    break;
                }

                case "4":
                {
                    Console.WriteLine("Количество строк: " + list.Count);
                    break;
                }

                case "5":
                {
                    for (int i = 0; i <= list.Count - 1; i++)
                    {
                        Console.Write(list[i] + "(#" + list.GetID(i) + ") ");
                    }
                    Console.WriteLine();
                    break;
                }

                case "6":
                {
                    uint id;
                    Console.Write("Введите ID элемента: ");
                    id = Convert.ToUInt32(Console.ReadLine());
                    if (list.GetNodeByID(id) == null)
                    {
                        Console.WriteLine("Узел c таким ID удален");
                        break;
                    }
                    Console.WriteLine("#{0}- " + list.GetNodeByID(id).Data, id);
                    break;
                }

                default:
                {
                    Console.WriteLine("Введенное значение не соответствует ни одной из команд, попробуйте еще раз");
                    break;
                }
                }
            }

            Environment.Exit(0);
            ConsoleKeyInfo pressed;

            pressed = Console.ReadKey();
            //if (pressed.KeyChar == 'y')


            Console.ReadKey();
        }
Exemple #30
0
 public PagerModel2(CountDelegate count) : this()
 {
     GetCount = new CountDelegate(count);
 }
 public void setCountDelegate(CountDelegate count)
 {
     GetCount = new CountDelegate(count);
 }
Exemple #32
0
 public void setCountDelegate(CountDelegate count)
 {
     GetCount = count;
 }
Exemple #33
0
 public PagerModel2(CountDelegate count)
     : this()
 {
     GetCount = count;
 }
Exemple #34
0
 public void SetAlo(CountDelegate algo)
 {
     algorithm = algo;
 }