public funcDelegate this[string index] { get { // if the value is not in the dictionary then we add a func that returns the value if (!funcDictionary.ContainsKey(index)) { funcDictionary.Add(index, num => num); } return(funcDictionary[index]); } // end of get set { // if the value is in the dictionary then we change the value if (funcDictionary.ContainsKey(index)) { funcDictionary[index] = new funcDelegate(value); } // if the value is not in the dictionary then we add it else { funcDictionary.Add(index, new funcDelegate(value)); } } // end of set }
static public double CubeMin(funcDelegate y, double x0, double _eps, out int k) { k = 1; eps = _eps; h = 0.01 * x0; if (h == 0) { h = 0.01; } double a, b; swann1(y, x0, out a, out b); double x1 = x0; double x = x0; for (int i = 0; i < 100; i++) { //основной этап //шаг 1 //1) double z = dy(a, y) + dy(b, y) + 3 * (y(a) - y(b)) / (b - a); double omega = Math.Pow((z * z - dy(a, y) * dy(b, y)), 0.5); double gamma = (z + omega - dy(a, y)) / (dy(b, y) - dy(a, y) + 2 * omega); //2) if ((gamma <= 1) && (gamma >= 0)) { x = a + gamma * (b - a); } else if (gamma < 0) { x = a; } else { x = b; } //шаг 2 if (Math.Abs(dy(x, y)) < eps || x == a || x == b) { break; } else if (dy(x, y) > 0) { b = x; } else { a = x; } k++; } return(x); }
static void Main(string[] args) { funcDelegate d1 = add; //funcDelegate d2 = mult; // short ways of referencing delegate funcDelegate d2 = d1; // funcDelegate d3 = new funcDelegate(mult); // longer way of assigning a reference Console.WriteLine("The sum 5 and 6 ", +d1(5, 6)); Console.WriteLine("The result of multiplying 5 and 6 ", +d2(5, 6)); Console.WriteLine("The result of multiplying 5 and 6 ", +d3(5, 5)); }
static void Main(string[] args) { funcDelegate d1 = addNum; funcDelegate d2 = addNum; if (d1 == d2) { Console.WriteLine("They are equal"); Console.ReadLine(); } }
static void Main(string[] args) { funcDelegate d1 = add; funcDelegate d2 = mult; funcDelegate d3 = d1 + d2; funcDelegate d4 = d2 + d1; d3(10, 20); d4(10, 20); Console.ReadKey(); }
/// 関数配列の呼び出し(引数byte[]型) public byte[] ComputeHash_Common(int i, byte[] var) { // 関数配列の宣言 funcDelegate func = HashFuncTables[i]; if (func != null) { return(func(var)); } else { return(null); } }
public bool registerHotkey(ModifierKeys_e controlKeys, Keys key, funcDelegate func) { bool registerOk = false; KeyboardHook hook = new KeyboardHook(); // register the event that is fired after the key press. hook.KeyPressed += new EventHandler <KeyPressedEventArgs>(func); try { hook.RegisterHotKey(controlKeys, key); registerOk = true; } catch (Exception ex) { registerOk = false; MessageBox.Show(ex.Message); } return(registerOk); }
static private void swann1(funcDelegate y, double x0, out double a, out double b) { int k = 1; double alpha = 0.01; double x = x0; //устанавливаем направление функции if (y(x + alpha) > y(x)) { alpha = -alpha; } while (k < 30) { if (y(x + alpha) > y(x)) { break; } else { x += alpha; alpha *= 2.0; k++; } } a = x - alpha / 2; b = x + alpha; if (a > b) { double t = a; a = b; b = t; } }
static private double dy(double x, funcDelegate y) { return((y(x + eps) - y(x - eps)) / (2 * eps)); }
public SingleMission(funcDelegate func, string name) { this.single_mission = func; this.Name = name; }
public bool registerHotkey(ModifierKeys_e controlKeys, Keys key, funcDelegate func) { bool registerOk = false; KeyboardHook hook = new KeyboardHook(); // register the event that is fired after the key press. hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(func); try { hook.RegisterHotKey(controlKeys, key); registerOk = true; } catch (Exception ex) { registerOk = false; MessageBox.Show(ex.Message); } return registerOk; }
/* * adds the fuctions all together */ public ComposedMission Add(funcDelegate func) { this.funcs_list.Add(func); return(this); }
public static void SetListener(this ButtonClickedEvent clickEvent, funcDelegate funcToExecute) { clickEvent.RemoveAllPersistantCalls(); clickEvent.AddListener(funcToExecute); }
} // end of Calculate // adding functions to the list public ComposedMission Add(funcDelegate func) { this.funcList.Add(func); return(this); } // end of Add
public static void AddOnClick(this Button button, funcDelegate funcToExecute) { button.onClick.AddListener(funcToExecute); }
public static void AddListener(this ButtonClickedEvent clickEvent, funcDelegate funcToExecute) { clickEvent.AddListener(new Action(() => { funcToExecute(); })); }
/// <summary> /// Add a function to the ThreadQueue. It will execute the thread immediately if the thread Instance for this class isn't running /// </summary> /// <param name="func">The function to be added to the TheadQueue and run as a thread</param> public static void AddToQueue(funcDelegate func, ApartmentState threadType = ApartmentState.Unknown, bool join = false) => AddToQueue(new Thread(() => func()), threadType, join);
public SingleMission(funcDelegate func, string name) { this.funcD = func; //this.missionType = "Single"; this.missionName = name; }