题目内容

使用修饰符可以防止从所修饰的类派生出其他类。

查看答案
更多问题

阅读程序,写出程序运行结果:class Program{static void Main(string[] args){Shape[] s = {new Rectangle("矩形",2.0,3.0),new Circle("圆",3.5)};foreach(Shape shape in s){shape.Show();}Console.ReadKey();}}public abstract class Shape{protected string name;public Shape(string name){this.name = name;}public abstract void Show();public abstract double Area();}public class Rectangle : Shape{protected double weight;protected double height;public Rectangle(string name,double w,double h) : base(name){this.weight = w;this.height = h;}public override void Show(){Console.WriteLine("Rectangle:{0},area:{1:N2}",name,weight * height);}public override double Area(){return weight * height;}}public class Circle : Shape{protected double radius;public Circle(string name,double r) : base(name){this.radius = r;}public override void Show(){Console.WriteLine("Circle:{0},area:{1:N2}",name,Math.PI * radius * radius);}public override double Area(){return Math.PI * radius * radius;}}

阅读程序,写出程序运行结果。public delegate int DemoDelegate(int num);class Tool{public static void IntSquare(int[] intArray, DemoDelegate dd){for (int i = 0; i < intArray.Length; i++){intArray[i] = dd(intArray[i]);}}}class Program{static void Main(string[] args){DemoDelegate dd = Square;int[] intArray = {2,4,6 };Tool.IntSquare(intArray, dd);for (int i = 0; i < intArray.Length; i++){Console.WriteLine(intArray[i]);}Console.Read();}static int Square(int num){return num * num;}}

阅读程序,写出程序运行结果。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;}}

答案查题题库