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

namespace NonGenericArrayListLimitations
{
    class Program
    {
        static void Main(string[] args)
        {
            #region First Example
            // The .NET Framework 1.1 way to create a list:
            System.Collections.ArrayList list1 = new System.Collections.ArrayList();
            list1.Add(3);
            list1.Add(105);

            System.Collections.ArrayList list2 = new System.Collections.ArrayList();
            list2.Add("It is raining in Redmond.");
            list2.Add("It is snowing in the mountains."); 
            #endregion

            #region Second Example
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            // Add an integer to the list.
            list.Add(3);
            // Add a string to the list. This will compile, but may cause an error later.
            list.Add("It is raining in Redmond.");

            int t = 0;
            // This causes an InvalidCastException to be returned.
            foreach (int x in list)
            {
                t += x;
            }
            
            #endregion

            #region Third Example
            // The .NET Framework 2.0 way to create a list
            List<int> list3 = new List<int>();

            // No boxing, no casting:
            list3.Add(3); 
            #endregion

            #region Fourth Example
            // Compile-time error:
            //list3.Add("It is raining in Redmond."); 
            #endregion
        }
    }
}
