public static void Main() { Test obj = new Test(); myDel d = obj.func; Console.WriteLine(Func(d)); }
public void InstanceDelegateTest() { var delegateBasic = new DelegateBasic(); reference += delegateBasic.SayYourNameInstance; reference(); }
static void Main(string[] args) { myDel myDelegate = myExp => myExp / 10; int intRes = myDelegate(110); Console.WriteLine("Output {0}", intRes); Console.ReadLine(); //Create an expression tree type //This needs System.Linq.Expressions Expression <myDel> myExpDel = myExp => myExp / 10; /* * Program t = new Program(); * System.Console.WriteLine(t.m.Mutate()); * System.Console.WriteLine(t.m.Mutate()); * System.Console.WriteLine(t.m.Mutate()); * * * var x = new object(); * * var b = x is FooBar; * * var fooBar = (FooBar)x;*/ }
private void button1_Click(object sender, EventArgs e) { delObj = new myDel(showMessage); th1 = new Thread(new ThreadStart(incr)); th1.IsBackground = true; th1.Start(); }
private void btnAdminAddUser_Click(object sender, EventArgs e) { myDel methods = RechargeGDV; methods += ResetTxt; try { string name = txtAdminName.Text; string lastName = txtAdminLname.Text; string pass = txtAdminPass.Text; string dui = txtAdminDUI.Text; DateTime dateTime = dtpAdminBirth.Value; string sqlFormattedDate = dateTime.ToString("yyyy-MM-dd"); int dept = cmbAdminDept.SelectedIndex + 1; if (name.Equals("") || pass.Equals("") || dui.Equals("")) { MessageBox.Show("Asegúrese de ingresar correctamente la información."); } else { UserDAO.CreateUser(pass, name, lastName, dui, sqlFormattedDate, dept); MessageBox.Show("Usuario creado correctamente.\nAsegúrese de guardar la contraseña."); methods.Invoke(); } } catch (Exception exception) { MessageBox.Show("Asegúrese de ingresar correctamente la información."); } }
static void Main(string[] args) { Console.WriteLine("Del--->Output using del"); myDel del = Delegates.add; Console.WriteLine(del(10, 12)); Console.WriteLine("Del--->Output using func"); Func <int, int, int> obj = Delegates.add; Console.WriteLine(obj(10, 1)); Console.WriteLine("Del--->Output using func lambda"); string name = "amol"; Func <string, string> convert = s => s.ToUpper(); Console.WriteLine(convert(name)); Console.WriteLine("Generics--->Output 1"); var result1 = Generics.compare <string>("A", "A"); Console.WriteLine(result1); Console.WriteLine("Generics--->Output 2"); var result2 = Generics.compare <int>(1, 2); Console.WriteLine(result2); Console.ReadLine(); }
public void DoSomeFun() { this.form.Show(); myDel del = new myDel(SetFormData); this.form.Invoke(del); }
public async Task <ObservableCollection <WeatherProperties> > scrapeData(myDel del) { string webUrl = @"https://weather.gc.ca/forecast/hourly/bc-84_metric_e.html"; WebClient webClient = new WebClient(); string rawHTML = await Task.Run(() => webClient.DownloadString(webUrl)); return(filterRawHTML(rawHTML, del)); }
private void btnSUB_Click(object sender, EventArgs e) { if (SetNumbers() == true) { DelegateTest = sub.SUB; txtbox3.Text = (DelegateTest(number1, number2)).ToString(); } }
public void MuliticastDelegateTest() { var delegateBasic = new DelegateBasic(); reference += delegateBasic.SayYourNameInstance; reference += DelegateBasic.SayYourName; reference(); }
private void tbnMUL_Click(object sender, EventArgs e) { if (SetNumbers() == true) { DelegateTest = mul.MUL; txtbox3.Text = (DelegateTest(number1, number2)).ToString(); } }
void UpdateListThread() { while (isdisabled) { myDel ud = new myDel(UpdateList); Invoke(ud); Thread.Sleep(50); } }
public static int MainMethod(string[] args) { MyClass mc = new MyClass(); myDel del = mc.Do; dynamic d = del; d(3); //We invoke the dynamic delegate return(Test.s_status ? 0 : 1); }
static void Main(string[] args) { myDel md = new myDel(start); md += stop; md(10); Console.ReadKey(); }
private void btnDIV_Click(object sender, EventArgs e) { if (SetNumbers() == true) { if (number2 != 0) { DelegateTest = div.DIV; txtbox3.Text = (DelegateTest(number1, number2)).ToString(); } } }
public void AddEvent(myDel ev) { if (eventAddPlane == null) { eventAddPlane = new myDel(ev); } else { eventAddPlane += ev; } }
public void AddEvent(myDel ev) { if (eventAddShark == null) { eventAddShark = new myDel(ev); } else { eventAddShark += ev; } }
public void AddLoco(myDel ev) { if (eventAddLoco == null) { eventAddLoco = new myDel(ev); } else { eventAddLoco += ev; } }
public void AddEvent(myDel ev) { if (eventAddBoat == null) { eventAddBoat = new myDel(ev); } else { eventAddBoat += ev; } }
private int Loop(int count) { myDel del = UpdateText; for (int i = 0; i < 10000; i++) { count++; this.count = count; this.Invoke(del); } return(count); }
static void Main(string[] args) { myDel md = add; md += sub; md += mul; md += div; myEvent += md; myEvent(100, 10); Console.Read(); }
public int AddNum(myDel f, int a) { try { return(f(a)); } catch { throw; } finally { int d = 5; } }
static void Main(string[] args) { Func <string, int, char> m; Action <double, int> act; myDel d1 = (q, x) => (q * x) / 2; int z = d1(1, 2); Console.Out.WriteLine(z); act = (d, i) => { }; act(0.1, 1); m = (s, t) => 'c'; }
delegate void Operation(int num); //method that returns void and receive a number static void Main(string[] args) { myDel del = new myDel(sayHello); //how to invoke delegate: del.Invoke(); //will invoke sayHello //syntax sugar of above myDel del2 = sayHello; del2(); //instead of invoke //how to chaindelegates Operation op = Double; op += Triple; //concat also the triple method op(2); //will invoke Double and Triple /* * ====================================== * Anonymous Methods & Lambda Expressions * ====================================== */ Operation op2 = (num) => { Console.WriteLine(num); };//sugar syntax that let us avoid form declaring a method /* * ====================================== * Generic Delegates * ====================================== */ //- Let us avoid of declaring a Delegate Type (for ex as we declared above Operation and myDel types) //Action - doesn't have a return value Action <int> action;//can contain methods that doesnt return value and has int as input action = Double; action(2); //will print 4 action += Triple; //concating another method action(3); //will print 6 and then 9 //Func - does have return value Func <int, string> func; //can contain methods that return string value and has int as input func = (int num) => { return(num.ToString()); }; //action and func can have many inputs as we want Action <int, string, double> action2 = (num, s, d) => Console.WriteLine($"{num}{s}{d}");; Console.ReadKey(); }
public List <Detail> Sort_DAL(myDel d, string departure1, string arrival1, DateTime date1) { List <Detail> list = getDetailSchedule_DAL(departure1, arrival1, date1); for (int i = 0; i < list.Count - 1; i++) { for (int j = i + 1; j < list.Count; j++) { if (d(list[i], list[j])) { Detail temp = list[i]; list[i] = list[j]; list[j] = temp; } } } return(list); }
public static int MainMethod(string[] args) { dynamic mc = new MyClass(); try { myDel del = mc.Do; del(3); //We invoke the dynamic delegate } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex) { bool ret = ErrorVerifier.Verify(RuntimeErrorId.BindPropertyFailedMethodGroup, ex.Message, "Do"); if (ret) { return(0); } } return(1); }
static void Main(string[] args) { Console.WriteLine("Enter a number:"); int number = 0; try { string num = Console.ReadLine(); number = Convert.ToInt32(num); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Hello World!"); myDel addd = (x) => x + 10; Console.WriteLine($"The number {number} plus 10 is {addd.Invoke(number)}"); myDel power = delegate(int x) { return(Math.Pow(x, 10)); }; Console.WriteLine($"The number {number} to power 10 is {power.Invoke(number)}"); }
static void Main(string[] args) { Name ssa = new Name("Tomer", "Boiman"); var trs = ssa.GetFullName(); var ds = Simplified("4/6"); var ad = IsPalindronOrDescendent(97358817); string k = ReverseAndNot(123); Call cv = new Call(); myDel m = new myDel((int a) => { return(a + 100); }); cv.AddNum(m, 5); int a; SomeFunc(out a); var ee = IsPalindrom(10901); var hh = 98697697 % 10; var kl = 98697697 / 10; CallCenter v = new CallCenter(); var b = new Call(); int fr = b.AddNum(m, 1); Bfunc(b); // int a = 10; Afunc(ref a); List <int> myList = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; foreach (var item in func(2, 10)) { Console.WriteLine(item); } Console.ReadLine(); }
public void StaticDelegateTest() { reference += DelegateBasic.SayYourName; reference(); }
public Firefighter(myDel del) { FireDel = del; }
void UpdateListThread() { while(isdisabled) { myDel ud = new myDel(UpdateList); Invoke(ud); Thread.Sleep(50); } }
static void Main(string[] args) { //return; // queue.Enqueue(new Concurrent() { UserName = "******" }); myDel del; Console.Write("请输入你要发送的信息:"); string getStr = Console.ReadLine(); return; switch (getStr) { case "1": { del = new myDel(Real); timer = 1 * 1000; } break; case "2": { del = new myDel(TenSecond); timer = 1 * 1000 * 10; } //getStr = "Hour##0376QN=20180914090600630;ST=31;CN=2011;PW=123456;MN=010AQMS01000GD0201804060;Flag=4;CP=&&DataTime=20180914090600;a34001-Rtd=67.04,a34001-Flag=N;a34004-Rtd=39.60,a34004-Flag=N;a34002-Rtd=53.00,a34002-Flag=N;Leq-Rtd=60.97,Leq-Flag=N;a01007-Rtd=0.0,a01007-Flag=N;a01008-Rtd=335,a01008-Flag=N;a01006-Rtd=30.4,a01006-Flag=N;B00008-Rtd=51.3,B00008-Flag=N;B00009-Rtd=99.3,B00009-Flag=N&&2580"; break; case "3": { del = new myDel(Minute); timer = 1000 * 60; } //getStr = "Real##0375QN=20180914090704440;ST=31;CN=2011;PW=123456;MN=010AQMS01000GD0201804071;Flag=4;CP=&&DataTime=20180914090700;a34001-Rtd=60.56,a34001-Flag=N;a34004-Rtd=36.90,a34004-Flag=N;a34002-Rtd=47.00,a34002-Flag=N;Leq-Rtd=61.65,Leq-Flag=N;a01007-Rtd=0.0,a01007-Flag=N;a01008-Rtd=53,a01008-Flag=N;a01006-Rtd=32.1,a01006-Flag=N;B00008-Rtd=46.3,B00008-Flag=N;B00009-Rtd=99.3,B00009-Flag=N&&24C0"; break; default: { del = new myDel(Real); timer = 1 * 1000; } //getStr = "d##0375QN=20180914090704440;ST=31;CN=2011;PW=123456;MN=010AQMS01000GD0201804071;Flag=4;CP=&&DataTime=20180914090700;a34001-Rtd=60.56,a34001-Flag=N;a34004-Rtd=36.90,a34004-Flag=N;a34002-Rtd=47.00,a34002-Flag=N;Leq-Rtd=61.65,Leq-Flag=N;a01007-Rtd=0.0,a01007-Flag=N;a01008-Rtd=53,a01008-Flag=N;a01006-Rtd=32.1,a01006-Flag=N;B00008-Rtd=46.3,B00008-Flag=N;B00009-Rtd=99.3,B00009-Flag=N&&24C0"; break; } Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(IPAddress.Parse("192.168.1.156"), 457); while (true) { getStr = del(); Byte[] bytes = Encoding.UTF8.GetBytes(getStr, 0, getStr.Length); int nRst = socket.Send(bytes); if (nRst == (int)SocketError.SocketError) { Console.WriteLine("发送失败"); } //socket.Close(); Thread.Sleep(timer); } }