All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Visual C++ 6.0教程:c++数据类型之枚举
HTML网页制作基础教程(3):常用标记讲解_[Html教程]
GridView列显示时间货币格式字符串_[Asp.Net教程]
mysql,设置,log,保留天数_mssql学习_编程技术
apache的几个设置(目录,权限等)_php资料_编程技术
ASP.NET技巧:一个通用的分页类_.net资料_编程技术
SQL循序渐进(8)删除记录_[SQL,Server教程]
扩展GridView控件(七)——改变通过CheckBox选中的行的样式_[Asp.Net教程]
深入理解SQL Server 中的错误处理_[SQL Server教程]
面向服务及其在互联系统策略中的角色_.net资料_编程技术
Reading number is top 10 pictures
XuRe xuan cool and refreshing photoes1
Nine school beauty star those gossip matters
Is said to be a Chinese female artist fame explicit pictures before2
Small QiShu -- ShuangShuangPan2
2012 national geographic daily picture1
Female model behind the bitterness, often being overcharged4
初吻给了谁?
Beautiful Japanese beauty(漂亮的日本美女)2
到南昌西站了3
In the world the most mysterious 21 place landscape4
Download software ranking
SP3 for SQL2000
WebService在.NET中的实战应用教学视频 → 第4集
Unix video tutorial20
jdk1.5
尖东毒玫瑰A
Tram sex maniac 2 (H) rar bag7
美女游泳记
电车之狼R
Unix video tutorial7
Tram sex maniac 2 (H) rar bag16
delv published in(发表于) 2014/1/10 6:29:25 Edit(编辑)
C#网络应用编程基础练习题与答案(三)_[Asp.Net教程]

C#网络应用编程基础练习题与答案(三)_[Asp.Net教程]

C#网络应用编程基础练习题与答案(三)_[Asp.Net教程]

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];
  }
  }


  输出结果:


  Test1


  This is a string.


  2. 编写一个控制台应用程序,定义一个类MyClass,类中包含有public、private以及protected数据成员及方法。然后定义一个从MyClass类继承的类MyMain,将Main方法放在MyMain中,在Main方法中创建MyClass类的一个对象,并分别访问类中的数据成员及方法。要求注明在试图访问所有类成员时哪些语句会产生编译错误。


  【解答】



  using System;
  class MyClass
  {
  public int i;
  private int j;
  protected int k;
  public void method1()
  {
  Console.WriteLine("public method.");
  }
  private void method2()
  {
  Console.WriteLine("private method.");
  }
  protected void method3()
  {
  Console.WriteLine("protected method.");
  }
  }
  class MyMain : MyClass
  {
  public static void Main()
  {
  MyClass t = new MyClass();
  Console.WriteLine("i={0}", t.i);
  Console.WriteLine("j={0}", t.j); //会出现编译错误,私有成员不允许在其它类中访问
  Console.WriteLine("k={0}", t.k); //会出现编译错误,应该创建MyMain的对象,然
  //后通过MyMain的对象访问
  t.method1();
  t.method2(); //会出现编译错误,私有的方法不允许在其它类中调用
  t.method3(); //会出现编译错误,应该创建MyMain的对象,然后通过MyMain的
  //对象调用该方法
  }
  }


  3. 创建一个类包含有protected数据。在相同的文件里创建第二个类,用一个方法操纵第一个类里的protected数据。


  【解答】



  using System;
  class Class1
  {
  protected int i = 5;
  protected void MyMethod()
  {
  Console.WriteLine("protected method.");
  }
  }
  class Class2 : Class1
  {
  private void NewMethod()
  {
  Console.WriteLine(this.i);
  this.i += 10;
  Console.WriteLine(this.i);
  }
  public static void Main()
  {
  Class2 t = new Class2();
  t.NewMethod();
  }
  }


  4. 分别写出下列语句执行的结果。


  1) Console.WriteLine("{0}--{0:p}good",12.34F);


  2) Console.WriteLine("{0}--{0:####}good",0);


  3) Console.WriteLine("{0}--{0:00000}good",456);


  【解答】


  12.34--1,234.00%good


  0--good


  456--00456good


  5. 编写一个控制台应用程序,计算


  要求精度为10-8。


  【解答】



  using System;
  class Test5
  {
  public static void Main()
  {
  int n = 50;
  double x = 3;
  double s = 0;
  double a = 1;
  for (int i = 1; i <= n; i++)
  {
  a *= i;
  s += Math.Pow(-1, i + 1) * Math.Pow(x, i) / a;
  }
  Console.WriteLine("n={0},s={1:0.00000000}", n, s);
  }
  }


  6. 编写一个控制台应用程序,接收一个长度大于3的字符串,完成下列功能


  1) 输出字符串的长度。


  2) 输出字符串中第一个出现字母a的位置。


  3) 在字符串的第3个字符后面插入子串“hello”,输出新字符串。


  4) 将字符串“hello”替换为“me”,输出新字符串。


  5) 以字符“m”为分隔符,将字符串分离,并输出分离后的字符串。


  【解答】



  using System;
  class Test6
  {
  public static void Main()
  {
  string str = "";
  while (str.Length <= 3)
  {
  Console.Write("请输入一个长度大于3的字符串:");
  str = Console.ReadLine();
  }
  //(1)
  Console.WriteLine("字符串的长度为:{0}", str.Length);
  //(2)
  int i = str.IndexOf('a');
  if (i > -1)
  {
  Console.WriteLine("第一个出现字母a的位置是:{0}", i);
  }
  else
  {
  Console.WriteLine("字符串中不包含字母a。");
  }
  //(3)
  string str1 = str.Insert(3, "hello"); //在第3个(初始序号为)字符前插入hello
  Console.WriteLine("插入hello后的结果为:{0}", str1);
  //(4)
  string str2 = str1.Replace("hello", "me");
  Console.WriteLine("将hello替换为me后的结果为:{0}", str2);
  //(5)
  string[] arr = str2.Split('m');
  Console.WriteLine("以m为分隔符分离后的字符串有:");
  for (int j = 0; j < arr.Length; j++)
  {
  Console.WriteLine(arr[j]);
  }
  }
  }





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.