四、程序分析题(5题共25分,每题5分)
1. 阅读代码并写出结果。
static void Main(string[] args){
byte[][] info = new byte[5][];
for (int i = 0; i < info.Length; i++){
info[i] = new byte[i+2];
}
for (int i = 0; i < info.Length; i++){
Console.WriteLine("第{0}行的长度是{1}",i,info[i].Length);
}
}2. 阅读代码并写出结果。
static void A(ref int x,ref int y,out int z){
int temp; temp = x; x = y; y = temp;
z = x - 100;
  Console.WriteLine("x = {0},y = {1}", x, y);
  Console.WriteLine("z = {0}",z);
}
static void Main(string[] args){
int m = 100; int n = 200;int k;
  A(ref m, ref n,out k);
  Console.WriteLine("m = {0},n = {1}", m, n);
}
3. 阅读代码并写出结果。
static double Compute(double x){
return x;
}
static double Compute(float x, double y){
return x + y;
}
static double Compute(double x, float y){
return x - y;
}
static double Compute(float x, float y){
return x * y;
}
static double Compute(double x, double y){
return x / y;
}
static void Main(string[] args){
Console.WriteLine(15);
Console.WriteLine(Compute(15.0f,15.0));
Console.WriteLine(Compute(15.0,15.0f));
Console.WriteLine(Compute(15.0f, 15.0f));
Console.WriteLine(Compute(15.0, 15.0));
}
4. 阅读代码并写出结果。
class Father {
public virtual void GotoWork() {
Console.WriteLine("Father goes to work");
}
}
class Son :Father {
public override void GotoWork() {
    Console.WriteLine("Son goes to work");
  }
}
class Test {
static void Main(string[] args){
Father f = new Father();
    Son s = new Son();
    Father other = new Son();
    f.GotoWork();
    s.GotoWork();
    other.GotoWork();
  }
}
5. 阅读代码并写出结果。
using System;
using Chinese = Animal.Mammal.Person;
namespace Animal{
    namespace Mammal{
        public class Person{
            public string ToString(){
                return "Person";
            }
        }
    }
}
namespace B{
    class Test{
        static void Main(string[] args){
            Chinese achinese = new Chinese();
            Console.WriteLine(achinese);
        }
    }
}
五、程序填空题(5题共25分,每题5分)
1. 下列程序实现了在控制台上输入一个成绩并在控制台上输出成绩的等级,根据要求填写下列程序的空白处。
static void Main(string[] args){
//从控制台输入一个整数
int num = Convert.ToInt32(____①____);  
string result = "";
switch(____②____){                         
____③____:                                
case 9: result = "优秀"; break;
    case 8: result = "良"; break;
    case 7: result = "中"; break;
    case 6: result = "及格"; break;
    ____④____: result = "不及格";          
 ____⑤____;                                  
  }
  Console.WriteLine(result);
}
2. 填写下列程序中的空白处。
class Plane{
int speed;
static int weight;
void Run() { }
static void Stop() { }
static void Main(string[] args){
    Plane p = ____①____;
    Plane.____②____ = 100;
    Plane.____③____;
    p.____④____ = 200;
    p.____⑤____;            
  }
}
3. 填写下列程序中的空白处。
class Viechle{
public Viechle() { }
  public void Run() { }
}
class Car : Viechle{
public Car()
      : ____①____//调用基类的构造方法
  { }
____②____ public void Run(){//隐藏基类的同名方法
  ____③____;//调用基类的Run方法
  }
}
4. 填写下列程序中的空白处。
abstract class A{        
public ____①____ string foo();        
}
class B : A {                
public ____②____ string foo(){
return "";
  }        
}
5. 在按钮事件处理程序中填写代码,在对话框中选择“保存”按钮后,实现处理流程序。
private void button1_Click(object sender, EventArgs e){
SaveFileDialog sfd = new SaveFileDialog();//创建对话框对象
____①____;//对话框中的文件类型为所有文件
if (____②____) {//点击“保存”按钮
    //处理流代码

}
对象String代码考试答案