题目内容

阅读程序,写出程序运行结果。using System;using System.Collections.Generic;public delegate void sayhellodelegate(string name);class Program{static void Main(string[] args){List pp = new List();pp.Add(new People { Name = "马大云", Country = "中国", sayfunction = Chinesenihao });pp.Add(new People { Name = "Bill Gat", Country = "USA", sayfunction = EnglishHello });pp.ForEach(p => Say(p));Console.ReadKey();}public static void Say(People p){p.sayfunction(p.Name);}public static void Chinesenihao(string name){Console.WriteLine("{0}:老表,吃饭没?",name);}public static void EnglishHello(string name){Console.WriteLine("{0}:hi,the weather is nice today.",name);}}public class People{public string Name { get; set; }public string Country { get; set; }public sayhellodelegate sayfunction { get; set; }}

查看答案
更多问题

阅读程序,写出程序运行结果。using System;public delegate double MyDelegate(double x,double y);class Program{static void Main(string[] args){//第1空MyDelegate md = new MyDelegate(Add);Console.WriteLine(md(2, 3));//第2空md = md + new MyDelegate(Minus);Console.WriteLine(md(2, 3));//第3空md = md + delegate(double x, double y) {Console.WriteLine(x*y);return x * y; };Console.WriteLine(md(2, 3));//第4空md = md - new MyDelegate(Minus);Console.WriteLine(md(2, 3));Console.ReadKey();}public static double Add(double x, double y){Console.WriteLine(x+y);return x + y;}public static double Minus(double x, double y){Console.WriteLine(x-y);return x - y;}}

阅读程序,写出程序运行结果。using System;delegate void MyDel(string value);class Program{void Print1(string value){Console.WriteLine("方法1:{0}", value);}void Print2(string value){Console.WriteLine("方法2:{0}", value);}void Print3(string value){Console.WriteLine("方法3:{0}", value);}/// /// 执行委托方法/// /// 委托类型参数/// 委托内方法的参数void PrintFun(MyDel d, string value){d(value);}static void Main(string[] args){Program p = new Program();MyDel del1, del2, del3;//声明委托变量//赋值del1 = p.Print1;del2 = p.Print2;//组合委托del3 = del1 + del2;//给委托赋新值del1 = p.Print2;//给委托添加方法del1 += p.Print3;//从委托移除方法del1 -= p.Print2;p.PrintFun(del1, "已运行");//调用Console.WriteLine("\n运行组合委托");p.PrintFun(del3, "已运行");Console.ReadKey();}}

阅读程序,写出程序运行结果:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace EventDemo{class Program{static void Main(string[] args){Ring schoolRing = new Ring();Student student1 = new Student("2018级计科1班");Student student2 = new Student("2018级计科2班");//schoolRing.OnBellSound = student1.DoSomething;//schoolRing.OnBellSound += student2.DoSomething;student1.AddRingEvent(schoolRing);student2.AddRingEvent(schoolRing);schoolRing.Jow(1);//第1空schoolRing.Jow(2); //第2空Console.ReadKey();}}class Ring{public delegate void RingEvent(int ringKind);public RingEvent OnBellSound;public void Jow(int ringKind){if (ringKind == 1 || ringKind == 2){Console.WriteLine(ringKind == 1 ? "上课铃响了:" : "下课铃响了:");if (OnBellSound != null){OnBellSound(ringKind);}}else{Console.WriteLine("铃声不正确");}}}class Student{private string className;public Student(string className){this.className = className;}private void DoSomething(int ringKind){if (ringKind == 1){Console.WriteLine(this.className + "的同学们开始上课了");}else{Console.WriteLine(this.className + "的同学们可以下课休息了");}}public void AddRingEvent(Ring ring){ring.OnBellSound += DoSomething;}public void RemoveRingEvent(Ring ring){ring.OnBellSound -= DoSomething;}}}

类时存储在()的引用类型;结构是存储在()的值类型

答案查题题库