1. 编写一个控制台应用程序,完成下列功能。
  1) 创建一个类,用无参数的构造函数输出该类的类名。
  2) 增加一个重载的构造函数,带有一个string类型的参数,在此构造函数中将传递的字符串打印出来。
  3) 在Main方法中创建属于这个类的一个对象,不传递参数。
  4) 在Main方法中创建属于这个类的另一个对象,传递一个字符串“This is a string.”。
  5) 在Main方法中声明类型为这个类的一个具有5个对象的数组,但不要实际创建分配到数组里的对象。
  6) 写出运行程序应该输出的结果。
  【解答】
  using System; 
  class Test1 
  { 
  public Test1() 
  { 
  Console.WriteLine(this); 
  } 
  public Test1(string str) 
  { 
  Console.WriteLine(str); 
  } 
  public static void Main() 
  { 
  Test1 t1 = new Test1(); 
  Test1 t2 = new Test1("This is a string."); 
  Test1[] t3 = new Test1[5]; 
  } 
  }
赞
If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
 
 
QQ:154298438
QQ:417480759