static void Main(string[] args)
        {
            MyArrayList list = new MyArrayList();

            list.Add("Ali");
            list.Add(22);
            list.Add("Sundus");
            list.Add(21);

            foreach (var item in list)
            {
                Console.WriteLine("{0}", item);
            }

            // Delay.
            Console.ReadKey();
        }
示例#2
0
        public YieldReturnDemo()
        {
            //1.
            ArrayList list = new ArrayList();

            list.Add("1");
            list.Add(2);
            list.Add("3");
            list.Add('4');

            Console.WriteLine(" == regualer ArrayList object ==");
            foreach (object s in list)
            {
                Console.WriteLine(s);
            }
            MyArrayList mylist = new MyArrayList();

            mylist.Add("1");
            mylist.Add(2);
            mylist.Add("3");
            mylist.Add('4');

            Console.WriteLine(" == IEnumerable  ArrayList object ==");
            foreach (object s in mylist)
            {
                Console.WriteLine(s);
            }

            //2.
            List <string> listOfString = new List <string>();

            listOfString.Add("one");
            listOfString.Add("two");
            listOfString.Add("three");
            listOfString.Add("four");

            Console.WriteLine(" == regualer List string ==");
            foreach (string s in listOfString)
            {
                Console.WriteLine(s);
            }
            MyList <string> mylistOfString = new MyList <string>();

            mylistOfString.Add("one");
            mylistOfString.Add("two");
            mylistOfString.Add("three");
            mylistOfString.Add("four");

            Console.WriteLine(" == IEnumerable<T> List string ==");
            foreach (string s in mylistOfString)
            {
                Console.WriteLine(s);
            }


            Console.WriteLine(" == reguler return will only return first one ==");
            Console.WriteLine(SimpleReturn());
            Console.WriteLine(SimpleReturn());
            Console.WriteLine(SimpleReturn());
            Console.WriteLine(SimpleReturn());
            Console.WriteLine(" == IEnumerable yield return will return all one by one ==");
            foreach (int i in YieldReturn())
            {
                Console.WriteLine(i);
            }
        }