首先申明,这个是我书上一个例子,有几个地方我真的是没看懂为什么这样做啊,请高手们能不能按我指出的一一给我指点下,非常感谢!用面向对象的程序设计方法求多个圆的面积
  public class mycircleclass
  {
  public const double pi = 3.1415926;
  private double area;
  public int[] radius;kl
  public mycircleclass(params int[] r)
  {
  this.radius = new int[r.Length];
  for (int i = 0; i < r.Length; i++)
  {
  this.radius[i] = r[i];
  }
  this.getarea += new EventHandler(this.mycrircleclass_getarea);
//这里这条语句是干什么的?跟后面的那个有关系啊!(书上解释是给事件注册方法)
  }
  public double Area
  {
  get
  {
  return this.area;
//这里是返回到this.area是返回到哪啊?什么意思呢?有什么用啊?  }
  set
  {
  this.area = value;
  }
  }
  public int this[int index]
  {
  get
  {
  return this.radius[index];
//这里是返回到this.radius是返回到哪啊?什么意思呢?有什么用啊?
  }
  set
  {
  this.radius[index]=value;
  }
  }
  private void mycrircleclass_getarea(object sender, EventArgs e)
{
int ind = (int)sender;
this.area = this.radius[ind] * this.radius[ind] * mycircleclass.pi;
}  
//上面的方法有什么意思呢?  
 
  public EventHandler getarea;
//上面一句是干嘛的啊?
  public void start(int ind)
  {
  getarea(ind, new EventArgs());
//这一句又是什么意思啊? }
  }
  public class Mainclass
  {
  public static void Main()
  {
  int[] r ={ 1, 2, 3, 5, 4 };
  mycircleclass mcc = new mycircleclass(r);
  for (int i = 0; i < r.Length; i++)
  {
  mcc.start(i);
  Console.WriteLine("滴{0}个圆的面积为:{1}", i + 1, mcc.Area);
  }
  }
  }
  }
大家能讲多少是多少,谢谢大家了!

解决方案 »

  1.   

    this.getarea += new EventHandler(this.mycrircleclass_getarea);
    这个是关联事件吧,也就是当事件激发时,调用相关联的方法
    return this.area;
    这是个属性定义,即获取属性Area的值
    return this.radius[index];
    这个是索引器的构造法private void mycrircleclass_getarea(object sender, EventArgs e)
    {
    int ind = (int)sender;
    this.area = this.radius[ind] * this.radius[ind] * mycircleclass.pi;

    这个是个无返回值的方法,主要用于定义属性area的值,即上面set的方法public EventHandler getarea;
    定义事件,上面第一语句就是为该事件关联对应的方法
      

  2.   

    关于C#的一些基本知识要先学习下  
    我看的第一本C#书是 《C#本质论》 
    感觉还不错  推荐下
      

  3.   

    this.getarea += new EventHandler(this.mycrircleclass_getarea);
    //自定义事件,自己指定要触发的事件
    ----------------------------------------------------------------
    private void mycrircleclass_getarea(object sender, EventArgs e)
    {
       int ind = (int)sender;
       this.area = this.radius[ind] * this.radius[ind] * mycircleclass.pi;

    //这是上面this.getarea要指定触发的事件
    --------------------------------------------------------------
    public void start(int ind)
      {
          getarea(ind, new EventArgs());
          //方法的调用 
      }
    ----------------------------------------
    return this.属性;
    //返回属性值
      

  4.   

    只是事件模型的应用而已,不了解 C# 的话就多查查 MSDN 吧!写个类不能算什么面向对象程序设计!
      

  5.   

     this.getarea += new EventHandler(this.mycrircleclass_getarea);
    //这里这条语句是干什么的?跟后面的那个有关系啊!(书上解释是给事件注册方法)
    通俗的讲,你可以把getarea看做一个方法,+= 把后面的事件注册给getarea,结果,getarea多了一个事件方法,当你调用getarea时,就会顺便执行+=后面的方法。public double Area
      {
      get
      {
      return this.area;
      }  
    //这里是返回到this.area是返回到哪啊?什么意思呢?有什么用啊? }
    你说返回啥呢,当然返回的是一个double类型的数值,调用Area属性的Get方法返回private的area值
    如果你看不懂就去看书吧,有些东西很简单,但不是一说你就懂的,这个你懂的  set
      {
      this.area = value;
      }
      }
      public int this[int index]
      {
      get
      {
      return this.radius[index];
    //这里是返回到this.radius是返回到哪啊?什么意思呢?有什么用啊?
    首先纠正你个错误,不是返回到那里,他返回的是一个int类型的数,这个方法叫啥玩意我忘了,好像叫什么什么索引啥的,
      }
      set
      {
      this.radius[index]=value;
      }
      }
      private void mycrircleclass_getarea(object sender, EventArgs e)
    {
    int ind = (int)sender;
    this.area = this.radius[ind] * this.radius[ind] * mycircleclass.pi;

    //上面的方法有什么意思呢? 
    圆的面积计算
      
      public EventHandler getarea;
    //上面一句是干嘛的啊?
    声明事件
      public void start(int ind)
      {
      getarea(ind, new EventArgs());
    //这一句又是什么意思啊? }
    乱了乱了 ,我不会我不懂我………………
      }
      public class Mainclass
      {
      public static void Main()
      {
      int[] r ={ 1, 2, 3, 5, 4 };
      mycircleclass mcc = new mycircleclass(r);
      for (int i = 0; i < r.Length; i++)
      {
      mcc.start(i);
      Console.WriteLine("滴{0}个圆的面积为:{1}", i + 1, mcc.Area);
      }
      }
      }
      }
    我来那个,你懂的