public void RawIteratorTest()
        {
            // 测试 IEnumerator
            int         count    = 0;
            RawIterator iterator = new RawIterator();

            foreach (int item in iterator)
            {
                Assert.AreEqual <int>(count++, item);
            }

            //测试具有参数控制的IEnumerable
            count = 1;
            foreach (int item in iterator.GetRange(1, 3))
            {
                Assert.AreEqual <int>(count++, item);
            }

            //测试手工捏出来的IEnumerable
            string[] data = new string[] { "hello", "world", "!" };
            count = 0;
            foreach (string item in iterator.Greeting)
            {
                Assert.AreEqual <string>(data[count++], item);
            }
        }
示例#2
0
        public void Iterator()
        {
            int         count    = 0;
            RawIterator iterator = new RawIterator();

            foreach (var item in iterator)
            {
                Assert.AreEqual <int>(count++, item);
            }
            count = 1;
            foreach (var item in iterator.GetRange(1, 3))
            {
                var s = item;
            }
            count = 0;
            foreach (var item in iterator.Greeting)
            {
                var s = item;
            }
        }