| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1874 人关注过本帖
标题:请教!!!
只看楼主 加入收藏
volte
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:69
帖 子:1167
专家分:1316
注 册:2004-12-19
收藏
得分:0 

using System; //引用System命名空间

public class MyCollection //创建一个类 MyCollection { int[] items; ///初始化

public MyCollection() //这条语句是继承 MyCollection 类的么? ///构造函数; { items = new int[5] {12, 44, 33, 2, 50}; 为什么不写成int items=new int[5]{12,44,33,2,50}呢?是整形变量的关键字可以省略的么? ///因为前面已经初始化了,所以直接调用赋值 }

public MyEnumerator GetEnumerator() { return new MyEnumerator(this); //return在这里具体的意思是什么?请指教,谢谢!!! ///很有可能是对类的指针返回; } public class MyEnumerator { int nIndex; MyCollection collection; //是类型的继承么? ///申明一个类 public MyEnumerator(MyCollection coll) //此类有什么意思,能解释下么?谢谢!!! ///应该 ///是重载; { collection = coll; nIndex = -1; }

public bool MoveNext() //请解释,谢谢!!! ///指向下一个,返回布尔型真还是假; { nIndex++; return(nIndex < collection.items.GetLength(0)); }

public int Current //请解释,谢谢!!! ///当前的属性.返回当前的数据字段 { get { return(collection.items[nIndex]); } } } }

public class MainClass { public static void Main() { MyCollection col = new MyCollection(); Console.WriteLine("Values in the collection are:");

// Display collection items: foreach (int i in col) { Console.WriteLine(i); } }

[此贴子已经被作者于2005-2-3 11:03:40编辑过]


大家都是朋友,有空就来坐坐!
2005-02-03 11:00
wangfulin
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-2-6
收藏
得分:0 

using System; //引用System命名空间

public class MyCollection //创建一个类 MyCollection { int[] items;

public MyCollection() //这条语句是继承 MyCollection 类的么?( 答:这是这个类的构造函数) { items = new int[5] {12, 44, 33, 2, 50}; 为什么不写成int items=new int[5]{12,44,33,2,50} 呢?是整形变量的关键字可以省略的么? ( 答:因为构造函数起到初始化次类的作用,所以此函数中的items指的就是此类中的items 如果前边加上int 就重复定义了) ------------------------------------------------------------------------------------------------------------------ 我也是只刚刚上道的菜鸟 希望以后多多指教

2005-02-06 23:06
快速回复:请教!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015540 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved