Example #1
0
        static void Main(string[] args)
        {
            #region Fundamentos
            Pessoa p1;
            p1.nome  = "ola1";
            p1.idade = 10;

            Pessoa p2;
            p2.nome  = "ola2";
            p2.idade = 11;

            Pessoa p3;
            p3.nome  = "ola3";
            p3.idade = 10;

            Pessoa[] novo = new Pessoa[20];
            novo[0] = p1;
            //novo[0] = "ola";      //é possível?

            string[] nomes = new string[] { "ola", "ole" };
            #endregion

            #region ArrayList
            ArrayList aux = new ArrayList();

            aux.Add("luis");
            aux.Add("luis");
            aux.Add(12);
            aux.Add(nomes);
            //aux.AddRange(nomes);//adiciona elementos no final do ArrayList
            aux.Add("benfica");
            aux.Add(p2);
            aux.Add(p1);

            Console.WriteLine("Size= " + aux.Count);
            aux.Remove("luis");
            Console.WriteLine("Index: " + aux.IndexOf(p1).ToString());
            Console.WriteLine("Existe Benfica: " + aux.Contains("benfica"));

            //mostrar arrayList
            for (int i = 0; i < aux.Count; i++)
            {
                if (aux[i].GetType() == typeof(Pessoa))
                {
                    Pessoa p = (Pessoa)aux[i];
                    Console.WriteLine("{0} - {1}\n", p.nome, p.idade);
                }
                else
                {
                    Console.WriteLine(aux[i].ToString());
                }
            }

            //acrecsenta a Queue ao ArrayList
            //aux.AddRange(myQueue);

            ShowII(aux, '\n');

            #endregion

            #region Queues

            // Declaring a Queue
            Queue q = new Queue();
            // Adds an element at the end of Queue i.e. Enqueue operation
            q.Enqueue("Pankaj");
            q.Enqueue(1);
            q.Enqueue(10.5);
            q.Enqueue(true);
            q.Enqueue('A');
            q.Enqueue("Benfica");
            q.Enqueue("Portinho");
            q.Enqueue("Braguinha");
            q.Enqueue(6000000);
            q.Enqueue("Tadinhos!!!");
            //Get the number of elements present in the Queue
            Console.WriteLine("Count : {0}", q.Count);
            Console.WriteLine();
            //Printing all the element of Queue
            Console.WriteLine("Elements in Queue : ");
            foreach (object obj in q)
            {
                Console.WriteLine(obj);
            }
            Console.WriteLine();
            //Exploe ShowII
            //Returns the "next" of the Queue without removing
            Console.WriteLine("End element of Queue : {0}", q.Peek());
            Console.WriteLine();
            //Removes and Returns the end element of the Queue i.e. Dequeue operation
            object TopElement = q.Dequeue();
            Console.WriteLine("Removing End element of Queue = {0}\nNow End element of Queue = {1}\n", TopElement, q.Peek());
            //Determines whether an element present or not in the Queue
            if (q.Contains("Benfica"))
            {
                Console.WriteLine("O Glorioso!");
            }
            else
            {
                Console.WriteLine("Não é clube...");
            }
            //Copies all queue to a new Array(object)
            Object[] ob = q.ToArray();
            Console.WriteLine();
            foreach (object obj in ob)
            {
                Console.WriteLine(obj);
            }
            //Adjust queue size...Trim the Queue
            q.TrimToSize();

            //More...
            ShowII(q, '\n');
            Console.WriteLine("(Peek)   \t{0}", q.Peek());
            Console.WriteLine("(Dequeue)\t{0}", q.Dequeue());
            ShowII(q, '\n');
            //Removes all the element from Queue
            q.Clear();
            Console.WriteLine();
            Console.WriteLine("Count : {0}", q.Count);
            Console.ReadKey();

            #endregion

            #region Stacks
            // Declaring a stack
            Stack st = new Stack();
            // Inserting an element at the top of stack i.e. Push operation
            st.Push("Benfica");
            st.Push(1);
            st.Push(10.5);
            st.Push(true);
            st.Push('A');
            //Get the number of elements contained in the stack
            Console.WriteLine("Count : {0}", st.Count);
            Console.WriteLine();
            //Printing all the element of stack
            Console.WriteLine("Element in stack : ");
            foreach (object obj in st)
            {
                Console.WriteLine(obj);
            }
            Console.WriteLine();
            //Returns the topmost element of the stack without removing
            Console.WriteLine("Top most element of stack : {0}", st.Peek());
            Console.WriteLine();
            //Removes and Returns the topmost element of the stack i.e. Pop operation
            Object TopElement1 = st.Pop();
            Console.WriteLine("Removing Top element of Stack = {0}\nNow Top element of stack = {1}\n", TopElement1, st.Peek());
            //Determines whether an element present or not in the stack
            if (st.Contains("Benfica"))
            {
                Console.WriteLine("O maior");
            }
            else
            {
                Console.WriteLine("Que clube estranho...");
            }
            //Copies the stack to a new Array(object)
            Object[] ob1 = st.ToArray();
            Console.WriteLine();
            foreach (object obj in ob1)
            {
                Console.WriteLine(obj);
            }
            //Removes all the element from stack
            st.Clear();
            Console.WriteLine();
            Console.WriteLine("Count : {0}", st.Count);
            Console.ReadKey();
            #endregion

            #region OrdenarCollections

            ArrayList n = new ArrayList();
            n.Add(12);
            n.Add(24);
            n.Add(7);
            n.Sort();

            n.Add("ola");

            //n.Add(new Pessoa());

            Console.WriteLine("Antes de Ordenar");
            Show(n);
            //n.Sort();                    //comparar do mesmo tipo...OK!


            Console.ReadKey();
            //n.Sort();                // Porque falha?
            n.Sort(new MyComparer(SortDirecc.Asc));

            Console.WriteLine("Depois de Ordenar");
            Show(n);

            Console.ReadKey();
            //#endregion

            #endregion

            #region Ordenar MyArrayList

            //MyArrayList m = new MyArrayList();
            MyArrayList m = new MyArrayList(2);         //Capacidade multiplos de 2


            //m.MyArr.Add("ola");
            m.MyArr.Add(p1);
            m.MyArr.Add(p2);
            m.MyArr.Add(p1);                            //A Capacidade (capacity) duplica sempre que se esgota a reservada inicialmente

            //m.MyArr.Sort(

            m.MyArr.Insert(0, p3);                      //Insere na posição 0...shift rigth das existentes
            m.MyArr.Remove(p1);
            m.MyArr.Add(p1);
            //m.MyArr.Remove(p1);

            //Antes de ordenar
            m.ShowCollection();


            m.MyArr.Sort(new MyComparer());             //para ordenar é necessário um "IComparer
            //depois de ordenar
            m.ShowCollection();

            Console.WriteLine("Existe P1? " + m.MyArr.Contains(p1).ToString());
            Console.WriteLine("Em que posição está P2?" + m.MyArr.IndexOf(p2).ToString());

            Console.WriteLine("Capacidade: " + m.MyArr.Capacity.ToString());
            Console.WriteLine("Elementos: " + m.MyArr.Count.ToString());

            Console.WriteLine(m.ShowCollectionAdvanced().ToString());
            #endregion

            #region Hashtable I

            Hashtable ht = new Hashtable();
            //inicializar
            //Hashtable ht = new Hashtable() { { 1, 2 }, { 2, "ok" } };

            //Adding item into HashTable
            ht.Add(1, "Benfica");
            ht.Add(12, "Porto");
            ht.Add(8, "Braga");
            ht.Add(4, "Outro");
            Console.WriteLine("Count : {0}", ht.Count);
            if (ht.ContainsValue("Benfica"))
            {
                Console.WriteLine("Benfica existe na HashTable");
            }
            else
            {
                ht.Add(5, "Benfica");
            }

            //Get a collection of values
            Console.WriteLine("Valores :");
            ICollection values = ht.Values;
            foreach (string str in values)
            {
                Console.WriteLine(str);
            }

            //Get a collection of Keys
            Console.WriteLine("Chaves:");
            ICollection keys = ht.Keys;
            foreach (int i in keys)
            {
                Console.WriteLine("Key: " + i + " Value: " + ht[i]);
            }
            ;
            ht.Remove(3);
            ht.Clear();

            // Put keys in an ArrayList.
            ArrayList arrayList = new ArrayList(ht.Keys);
            foreach (int key in arrayList)
            {
                Console.WriteLine(key);
            }
            Console.ReadKey();
            #endregion

            #region HashTable II
            MyHashTable h = new MyHashTable();

            //h.MyHash.Add(p1.nome, p1);
            //h.MyHash.Add(p2.nome, p2);

            //Console.WriteLine(((Pessoa)(h.MyHash[p1.nome])).nome);

            //Console.WriteLine("Contem chave ? " + h.MyHash.ContainsKey(p3.nome));
            //Console.WriteLine("Número de chaves ? " + h.MyHash.Count.ToString());

            //h.MyHash.Clear()                //limpa hash

            Console.WriteLine(h.ShowHash());

            Console.WriteLine(h.MyGetHashCode(p1.nome, 50));
            Console.WriteLine(h.MyGetHashCode(p2.nome, 50));
            Console.WriteLine(h.MyGetHashCode(p3.nome, 50));

            h.MyInsert(p1);
            h.MyInsert(p2);
            h.MyInsert(p3);
            h.MyInsert(p1);         //colisão!

            #endregion

            #region Arrays

            Array a = Array.CreateInstance(typeof(string), 20);

            a.SetValue("Benfica", 0);
            a.SetValue("Porto", 1);

            string s1 = (string)a.GetValue(0);

            #endregion

            #region SortedList

            Console.WriteLine("\nSortedList\n");
            SortedList sl = new SortedList();

            sl.Add(1, "Benfica");
            sl.Add(3, "Porto");
            sl.Add(4, "Braguinha");
            sl.Add(2, "Sporting");

            Console.WriteLine("Número de Elementos : {0}", sl.Count);
            if (sl.ContainsValue("Benfica"))
            {
                Console.WriteLine("Benfica é o maior");
            }
            else
            {
                sl.Add(1, "Benfica");
            }
            Console.WriteLine("Valor e chave na posição 3 = {0} , {1}", sl.GetByIndex(3), sl.GetKey(3));

            //Percorre a SortedList...mostra todas as chaves
            Console.Write("Chaves: ");
            foreach (int i in sl.Keys)
            {
                Console.Write(i + " ");
            }


            //Agrupa pares (k,v)
            IList keys1   = sl.GetKeyList();
            IList values1 = sl.GetValueList();
            Console.WriteLine("\nValores :");
            foreach (object obj in values1)
            {
                Console.WriteLine(obj);
            }
            //Or
            Console.WriteLine("\nChaves: Valores :");
            foreach (object obj in keys1)
            {
                Console.WriteLine("Chave: " + obj + " Valor: " + sl[obj]);
            }

            Console.WriteLine("Index do Porto é : {0}", sl.IndexOfValue("Porto"));

            //Mostra todos os pares (k,v)

            foreach (object obj in keys1)
            {
                Console.WriteLine("Key: {0} - Valor: {1}\n", obj, sl[obj]);
            }


            //Remover
            //remove elemento com chave 3
            sl.Remove(3);
            // Remove um elemento num determinado index
            sl.RemoveAt(2); //?

            Console.ReadKey();

            #endregion


            #region Carros

            ArrayList carros = new ArrayList();

            carros.Add(new Carro("19-12-12"));
            carros.Add(new Carro("12-12-13"));
            carros.Add(new Carro("13-12-12"));

            foreach (Carro c in carros)
            {
                Console.WriteLine("Mat= " + c.matricula);
            }

            carros.Sort(new MyComparer());

            foreach (Carro c in carros)
            {
                Console.WriteLine("Mat= " + c.matricula);
            }

            #endregion
        }
        static void Main(string[] args)
        {
            //ArrayList


            ArrayList al = new ArrayList();
            int       a  = 101;

            al.Add(a);
            al.Add("This is a arraylist");
            al.Add(2.3f);
            al.Insert(3, "This is the forth index");

            ArrayList al2 = new ArrayList();

            al2.Add(102);
            al.InsertRange(1, al2);
            Console.WriteLine("ArrayList:");
            Console.WriteLine();
            foreach (var ele in al)
            {
                Console.WriteLine(ele + " ");
            }
            Console.WriteLine("The count of the arraylist is {0}", al.Count);
            Console.WriteLine("The capacity of the arraylist is {0}", al.Capacity);
            Console.WriteLine();
            // Hash table

            Hashtable ht = new Hashtable();

            ht.Add(1, "one");
            ht.Add(2, "two");
            ht.Add(0.3f, 2);
            ht.Add(4, null);
            ht.Add("Hema", "vathi");
            ht.Remove(2);
            // ht.Clear();
            Console.WriteLine("Hashtable:");
            Console.WriteLine();
            foreach (DictionaryEntry ele in ht)   //ht.keys means only print a key values for values the viceversa is applied.
            {
                Console.WriteLine("{0},{1}", ele.Key, ele.Value);
            }
            String firstelement = (string)ht[1];
            String str          = (string)ht["Hema"];

            Console.WriteLine("The first element in the hashtable is {0}", firstelement);
            Console.WriteLine("The last element in the hashtable is {0}", str);
            Console.WriteLine("The hash table contains a 0.3  is {0}", ht.Contains(0.3f));
            Console.WriteLine();

            //SortedList
            Console.WriteLine("Sorted List:");
            SortedList sl = new SortedList();

            sl.Add(2, "two");
            sl.Add(1, "one");
            sl.Add(0, "zero");
            sl.RemoveAt(0);
            foreach (DictionaryEntry i in sl)
            {
                Console.WriteLine("{0},{1}", i.Key, i.Value);
            }
            Console.WriteLine();

            //stack

            Console.WriteLine("Stack:");
            Stack s = new Stack();

            s.Push("hello");
            s.Push(102);
            s.Push(102);
            s.Push(.3f);
            foreach (var item in s)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("The first element will be deleted is {0} ", s.Peek());
            Console.WriteLine();

            //Queue

            Console.WriteLine("Queue:");
            Queue q = new Queue();

            q.Enqueue(34);
            q.Enqueue("thirtyfour");
            q.Enqueue(3.4);
            q.Dequeue();
            foreach (var item in q)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("The first element of the queue is {0}", q.Peek());
        }
Example #3
0
        static void Main(string[] args)
        {
            int    a = 10;
            string b = "Hello";
            float  c = 2.32f;
            char   d = 'd';
            bool   e = true;

            int[] f = new int[6] {
                1, 2, 3, 4, 5, 6
            };
            ArrayList Array1 = new ArrayList();
            ArrayList Array2 = new ArrayList()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            Array1.Add(a);
            Array1.Add(b);
            Array1.Add(c);
            Array1.Add(d);
            Array1.Add(e);
            Array1.Add(f);
            Array1.Add("bcd");

            var dcd = Array1[6];     //Just for the sake of explicit typecasting

            Array1.Insert(0, a * 2); //inserting value a*2 at 0 index
            //by inserting every value will be pushed forward to the next location.

            Array1.AddRange(Array2);//adding another array list at the end of the first array list

            for (int i = 0; i < Array1.Count; i++)
            {
                Console.WriteLine("Value from {0} index ", i);
                Console.WriteLine(Array1[i]);
            }
            Console.WriteLine("\n Ended The array List Now moving towards next Collection \n\n\n");


            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


            //Code for Sorted List (Non generic)
            Console.WriteLine("From Sorted List Nongeneric");
            int        j       = 0;
            SortedList myNames = new SortedList();

            myNames.Add(j, a);
            j++;
            myNames.Add(j, b);
            j++;
            myNames.Add(j, c);
            j++;
            myNames.Add(j, d);
            j++;
            myNames.Add(j, e);
            j++;
            myNames.Add(j, f);
            j++;

            Console.WriteLine("Before removing an element");
            foreach (DictionaryEntry variable in myNames)
            {
                Console.WriteLine("{0} {1}", variable.Key, variable.Value);
            }

            myNames.RemoveAt(0);
            Console.WriteLine("After removing an element");
            foreach (DictionaryEntry variable in myNames)
            {
                Console.WriteLine("{0} {1}", variable.Key, variable.Value);
            }



            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Code for Sorted List (Generic)
            Console.WriteLine("\n\n\n From Sorted List Generic");
            j = 0;
            SortedList <int, string> myNames1 = new SortedList <int, string>();

            myNames1.Add(j, "a");
            j++;
            myNames1.Add(j, "b");
            j++;
            myNames1.Add(j, "c");
            j++;
            myNames1.Add(j, "d");
            j++;
            myNames1.Add(j, "e");
            j++;
            myNames1.Add(j, "f");
            j++;

            myNames1.Remove(1);
            foreach (var variable in myNames1)
            {
                Console.WriteLine("The value against key {0} is {1}", variable.Key, variable.Value);
            }

            Console.WriteLine("\n\n\n Using KeyValuePair Property");

            foreach (KeyValuePair <int, string> obj in myNames1)
            {
                Console.WriteLine("{0} {1}", obj.Key, obj.Value);
            }
            string result;

            if (myNames1.TryGetValue(2, out result))
            {
                Console.WriteLine("true {0}", result);
            }
            //Console.WriteLine(myNames1[0]);



            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Code for Dictionary implementation starts here
            Console.WriteLine("\n\n\n From Dictionary");

            Dictionary <char, string> dict = new Dictionary <char, string>();

            dict.Add('a', "Ali");
            dict.Add('b', "Batman");
            dict.Add('c', "Cat");
            dict.Add('d', "Dog");
            dict.Add('e', "Elephant");
            dict.Add('f', "Frog");
            foreach (Object obj in dict)
            {
                Console.WriteLine(obj);
            }

            dict.Add('g', "Goose");
            dict.Remove('a');

            Console.WriteLine("\n\n From Dictionary Generic Printing Count of objects");
            Console.WriteLine(dict.Count);

            Console.WriteLine("\n\n\n From Dictionary Generic using Object");
            foreach (Object obj in dict)
            {
                Console.WriteLine(obj);
            }
            Console.WriteLine("\n\n\n From Dictionary Generic using KeyValuePair");
            foreach (KeyValuePair <char, string> obj in dict)
            {
                Console.WriteLine("{0} {1}", obj.Key, obj.Value);
            }



            //Code for HashTable implementation starts here
            Console.WriteLine("\n\n\n From Hashtable");

            Hashtable hash = new Hashtable();

            hash.Add(1, a);
            hash.Add('a', b);
            hash.Add('b', b);
            hash.Add('d', b);
            foreach (DictionaryEntry obj in hash)
            {
                Console.WriteLine("{0} {1}", obj.Key, obj.Value);
            }
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


            //Code for List implementation starts here
            Console.WriteLine("\n\n\n From List generic");

            List <int> myList = new List <int>();

            myList.Add(1);
            myList.Add(21);
            myList.Add(2);
            myList.Add(0);
            myList.Sort();
            for (int i = 0; i < myList.Count; i++)
            {
                Console.WriteLine(myList[i]);
            }
            myList.RemoveAt(0);
            myList.Insert(0, 20);
            myList.Sort();
            for (int i = 0; i < myList.Count; i++)
            {
                Console.WriteLine(myList[i]);
            }


            List <ArrayList> myCollector = new List <ArrayList>();

            myCollector.Add(Array1);
            myCollector.Add(Array2);
            Console.WriteLine("\n\n" + myCollector[0].ToArray().Length);


            //Adding dummy student data into the list of students


            int                age;
            float              cgpa;
            string             name;
            string             email;
            string             address;
            string             contactNumber;
            List <StudentInfo> myClass = new List <StudentInfo>();
            StudentInfo        bacs    = new StudentInfo();

            myClass.Add(bacs);
            myClass.Add(bacs);
            for (int i = 0; i < 0; i++)
            {
                Console.WriteLine("Write the age of {0} student", i + 1);
                age = int.Parse(Console.ReadLine());
                Console.WriteLine("Write the cgpa of {0} student", i + 1);
                cgpa = float.Parse(Console.ReadLine());
                Console.WriteLine("Write the name of {0} student", i + 1);
                name = Console.ReadLine();
                Console.WriteLine("Write the email of {0} student", i + 1);
                email = Console.ReadLine();
                Console.WriteLine("Write the address of {0} student", i + 1);
                address = Console.ReadLine();
                Console.WriteLine("Write the contactNumber of {0} student", i + 1);
                contactNumber = Console.ReadLine();

                myClass.Add(new StudentInfo(age, cgpa, name, email, address, contactNumber));
            }
            foreach (StudentInfo s in myClass)
            {
                if (s.AGE >= 18)
                {
                    Console.WriteLine("The student details are as follow");
                    Console.WriteLine("The Name of the student is {0}", s.NAME);
                    Console.WriteLine("The Age of the student is {0}", s.AGE);
                    Console.WriteLine("The Cgpa of the student is {0}", s.CGPA);
                    Console.WriteLine("The Email of the student is {0}", s.EMAIL);
                    Console.WriteLine("The Address of the student is {0}", s.ADDRESS);
                    Console.WriteLine("The Contact Number of the student is {0}", s.CONTACTNUMBER);
                }
            }
            var results = from StudentInfo in myClass
                          where StudentInfo.AGE >= 12
                          select StudentInfo;

            Console.WriteLine("Student with age greater then 12 are as follow");

            foreach (StudentInfo s in results)
            {
                Console.WriteLine(s.AGE);
            }

            /*
             * myClass.Select(x=>new object { name=x.Total})
             *
             * var results = from s in myClass
             *            select s;
             *
             * foreach(StudentInfo info in myClass)
             *  {
             * Console.WriteLine(results[0]);*/


            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ///


            //Code for Stack implementation starts here
            Console.WriteLine("\n\n\n Implementation of Stack starts from here \n");
            Stack <int> myStack = new Stack <int>(f);


            Console.WriteLine("\nStack after entering values using array \n");
            foreach (int variable in myStack)
            {
                Console.Write(variable + ",");
            }
            Console.WriteLine();


            Console.WriteLine("\nStack after entering Value using push \n");
            myStack.Push(20);
            foreach (int variable in myStack)
            {
                Console.Write(variable + ",");
            }


            Console.WriteLine("\nStack after Peeking from it \n");
            Console.WriteLine(myStack.Peek());
            foreach (int variable in myStack)
            {
                Console.Write(variable + ",");
            }


            Console.WriteLine("\nStack after popping element from it \n");
            Console.WriteLine(myStack.Pop());
            foreach (int variable in myStack)
            {
                Console.Write(variable + ",");
            }
            Console.WriteLine();
            int check = 24;

            if (myStack.Contains(check))
            {
                Console.WriteLine("true the stack contains the value {0}", check);
            }
            else
            {
                Console.WriteLine("False the stack doesnot contains the value {0}", check);
            }


            //Iplementation of queue starts from here
            Queue <int> myQueue = new Queue <int>(f);

            Console.WriteLine("\nQueue after entering values from array");
            foreach (int variable in myQueue)
            {
                Console.Write(variable + ",");
            }

            myQueue.Enqueue(20);
            Console.WriteLine("\n\nQueue after using enqueue");
            foreach (int variable in myQueue)
            {
                Console.Write(variable + ",");
            }



            Console.WriteLine("\n\nQueue after Dequeue method");
            Console.WriteLine("The value returned from the dequeue method is " + myQueue.Dequeue());
            foreach (int variable in myQueue)
            {
                Console.Write(variable + ",");
            }


            Console.WriteLine("\n\nPrinting the count of elements in the queue \n" + myQueue.Count());

            Console.WriteLine("\nQueue after Peeking from it");
            Console.WriteLine("Value returned from peek method is " + myQueue.Peek());
            foreach (int variable in myQueue)
            {
                Console.Write(variable + ",");
            }

            Console.WriteLine();

            ///////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////
            ///////////////////////////////////////////////////////////////
            //File Hanlding
            string path1 = @"C:\Users\Lenovo\source\repos\Collections\Collections\bin\Debug\netcoreapp3.1/DummyData1.txt";
            string path2 = @"C:\Users\Lenovo\source\repos\Collections\Collections\bin\Debug\netcoreapp3.1/DummyData2.txt";
            string path3 = @"C:\Users\Lenovo\source\repos\Collections\Collections\bin\Debug\netcoreapp3.1/DummyData3.txt";

            string Abc  = "Hello from the file1";
            string Abcd = "Hello from the file2";

            /*File.WriteAllText(path1,Abc);
             * File.WriteAllText(path2, Abcd);
             */
            string DataRead = File.ReadAllText(path1);

            Console.WriteLine(DataRead);

            //This block is used to to auto close the file after the use
            //the file will open at the start of the using block and
            //At the end of the block the file is automatically closed.

            /*using (StreamWriter sw = File.AppendText(path1))
             * {
             *  sw.WriteLine("\nHello once again using Stream Writer");
             * }
             *
             * using (StreamReader sr = File.OpenText(path2))
             * {
             *  string readed = "";
             *  while ((readed = sr.ReadLine()) != null)
             *  {
             *      Console.WriteLine(readed);
             *  }
             * } */

            DataRead = File.ReadAllText(path1);
            Console.WriteLine("\n\n" + DataRead + "\n\n");

            DataRead = File.ReadAllText(path2);
            Console.WriteLine("\n\n" + DataRead + "\n\n");


            /*FileStream file = new FileStream(path3, FileMode.OpenOrCreate , FileAccess.ReadWrite);
             * //file.Write("Hello")
             * file.WriteByte(66);
             * file.Close();
             */
            using (FileStream file1 = new FileStream(path3, FileMode.Append, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(file1, Encoding.UTF8))
                {
                    int[] arrays = new int[10] {
                        1, 2, 3, 4, 5, 6, 7, 8, 9, 10
                    };
                    foreach (int num in arrays)
                    {
                        sw.Write(num + " ");
                    }

                    sw.WriteLine("\nHelpppp");
                }
            }


            using (FileStream file1 = new FileStream(path3, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(file1))
                {
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        Console.WriteLine(line);
                        line = sr.ReadLine();
                    }
                }
            }



            //Exception Handling Code
            int[] except = new int[3] {
                1, 2, 3
            };
            try
            {
                Console.WriteLine(except[10]);
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }
            finally
            {
                Console.WriteLine("The try catch Block has ended");
            }

            /*using (FileStream fs = new FileStream(path1, FileMode.Open, FileAccess.Read))
             * {
             *  using(StreamWriter stw = new StreamWriter(fs))
             *  {
             *
             *  }
             *
             *  using(StreamReader str = new StreamReader(fs))
             *  {
             *
             *  }
             *
             * }*/



            //Manipulating the tuples in the form of an array
            Tuple <int, float, double, char, string>[] studentTuples = new Tuple <int, float, double, char, string> [2];

/*            Tuple<int, float, double, char, string>[] studentFiltered = new Tuple< int, float, double, char, string>[2];
 */
            for (int i = 0; i < 2; i++)
            {
                studentTuples[i] = new Tuple <int, float, double, char, string>(1, 2.2f, 3.3, 'a', "abcd");
            }

            /*int iterator=0;*/
            foreach (Tuple <int, float, double, char, string> tp in studentTuples)
            {
                /*if (tp.Item5.Length >= 3)
                 * {
                 *  studentFiltered[iterator] = tp;
                 *  iterator++;
                 * }*/
                Console.Write(tp.Item1 + " , ");
                Console.Write(tp.Item2 + " , ");
                Console.Write(tp.Item3 + " , ");
                Console.Write(tp.Item4 + " , ");
                Console.WriteLine(tp.Item5);
            }
            //var v1 = new Tuple.Create(1,2);



            //Manilulating with the string array using LINQ queries
            string[] myNamesArray = new string[22] {
                "Ali", "Yar", "Wamik", "Afaq", "Salal", "Daniel", "June", "Juliet",
                "danyyal", "Yousuf", "Bukht", "Yar", "Arshad", "Kainat", "aiman", "sidra",
                "Tooba", "zeeshan", "Hyper", "Don", "Chaudary", "Muaaz"
            };
            var MyQueryResult = from names in myNamesArray
                                where names.Length >= 3
                                select names;

            Console.WriteLine("name---first2letters--Caps--length");
            foreach (var names in MyQueryResult)
            {
                Console.Write(names + " ");
                Console.Write(names.Substring(0, 2) + " ");
                Console.Write(names.ToUpper() + " ");
                Console.WriteLine(names.ToUpper().Length);
            }



            //Maipulatin with Tuple array using the LINQ queries
            var myTupleResults = studentTuples.Where(tuples => tuples.Item5.Substring(0, 2) == "ab" && tuples.Item5.Contains('b') && tuples.Item1 == 1);


            //We can write queries in Two ways

            /*from tuples in studentTuples
             * where tuples.Item5.Substring(0, 2) == "ab" && tuples.Item5.Contains('b') && tuples.Item1==12
             * select tuples;*/

            //Getting array in the resul of LINQ Queries
            var myTupleResultsArray = studentTuples.Where(tuples => tuples.Item5.Substring(0, 2) == "ab" && tuples.Item5.Contains('b') && tuples.Item1 == 1).ToArray();

            Console.WriteLine(myTupleResultsArray[0]);



            Console.WriteLine("\n\n From Tuples results\nName---first2letters--Caps--length");
            foreach (var tuples in myTupleResults)
            {
                Console.Write(tuples.Item1 + " ");
                Console.Write(tuples.Item2 + " ");
                Console.Write(tuples.Item3 + " ");
                Console.Write(tuples.Item4.ToString() + " ");
                Console.WriteLine(tuples.Item5.Substring(0));
            }
            Program pg = new Program();

            MakeNoise mk = new MakeNoise(pg.Noise);

            mk(10);
        }