C# 系列,这里是C#高级编程里面的,里面用了个索引符,没有明白到是啥意思哦。今天太晚了不想弄了。...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    public class Studuent : IEnumerable
    {
        private object[] temp = new object[100];
        private string name;
        private int number;
        public Studuent()
        {
            this.name = null;
            this.number = 0;
        }
        public Studuent(string Name, int Number)
        {
            this.number = Number;
            this.name = Name;

        }

        public string this[uint i]
        {
            get
            {
                return temp[i];
 
            }
            set
            {
                temp[i] = value;
            }
        }

       

 

        #region IEnumerable 成员

        public IEnumerator GetEnumerator()
        {
            return new StudentEnumerator(this);
        }

        #endregion
    }

    public class StudentEnumerator : IEnumerator
    {
        Studuent theStudent;
        int location;

        public StudentEnumerator(Studuent thestudent)
        {
            this.theStudent = thestudent;
            location = -1;

        }

 

        #region IEnumerator 成员

        public object Current
        {
            get
            {
                if (location < 0 || location > 2)
                    throw new InvalidOperationException("不在集合中");
                return theStudent[(uint)location];

            }
        }

        public bool MoveNext()
        {
            ++location;
            return (location > 2) ? false : true;
        }

        public void Reset()
        {
            this.location = -1;
        }

        #endregion
    }
    class Program
    {
        static void Main(string[] args)
        {
            Studuent[] stu = new Studuent()[100];

        }
    }
}

转载于:https://www.cnblogs.com/fat_li/archive/2010/09/20/1831412.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值