Пример #1
0
        public static void Print_using_orderby(GridSortOptions sort)
        {
            var temp = CommonCollections.IEGetAllCats();

            temp = temp.OrderBy(sort.Column, sort.Direction);
            foreach (CommonCollections.Cat c in temp)
            {
                Console.WriteLine(PrintCats(c));
            }
            Console.ReadKey();
        }
Пример #2
0
        /* Called by ReferenceTypes.cs
         */
        public static void Menu()
        {
            int x = 0;

            do
            {
                /*
                 *
                 * For Each versus using 'For' loop
                 *
                 * A foreach is readonly
                 * If you want to make modifications you have to use a for loop instead of a foreach
                 *
                 * But that does'n't mean individual elements are readonly, if the element contains
                 * reference types you can still modify their values, can't demonstrate that with strings
                 * because strings are immutable(unable to be changed or a value type, even though a string
                 * is a reference type).   But can be done with an an array
                 * of a reference type that is mutable (able to be changed).
                 *
                 * for each loop
                 * - can't replace elements
                 * - can modify values of elements - Array/Lists elements are read only.  But the element
                 *   properties can be modified e.g. You can change a word from lowercase to uppercase
                 * - cannot modify the index
                 * - only need one loop
                 * - Must iterate through all elements of a list
                 *
                 * for loop
                 * - can replace elements
                 * - Needed for nested loops
                 *
                 *
                 *
                 * Arrays versus Lists
                 *
                 * Arrays.
                 *  1.  Fixed Length.  Are Definined, so you cannot add to array on the fly.
                 *      If you want to add on the fly you have to use a List.
                 *  2.  Single Dimension array can be used with a foreach
                 *  3.  Strongly typed
                 * Lists.
                 *  1. Expandable - can add, insert, or remove elements
                 *  2. Multi-Dimensional.  A List cannot have more than one index.
                 *     Have to use a Multi-Dimensional Array if you want more than one index.
                 *  3. A list can be used with a foreach.
                 *  4. Strongly typed
                 *
                 * ArrayList
                 *  - Represents an ordered collection of an object that can be indexed
                 *    individually.  An Alternative to an array.  However, unlike an array
                 *    you can add and remove items from a list at a specified position using
                 *    an index and the array resizes itself automatically.  Allows dynamic memory
                 *    allocation, adding, searching and sorting items in the list.
                 *    https://www.tutorialspoint.com/csharp/csharp_arraylist.htm
                 *    List<T> is a generic version of ArrayList See GenericExamples.cs
                 *
                 *    C# is not like c++ where objects are destroyed when they go out of scope.
                 *    Instead, the Garbage Collector looks for objects which are completely unreferenced at
                 *    the current point of execution. Because the second function has a reference to the
                 *    arraylist, the arraylist and all its contents can't be garbage collected
                 *    while the second function is executing.
                 *
                 * Multi-Diminesional Arrays.
                 *  1.  Can have more than one index.
                 *  2.  Follow the x,y coordinates for a 2 dimensional array.  Great for grid based data
                 *  3.  Must use a 'for' loop for nested loops
                 *  4.  float [ , ] array1  -  defines a 2 dimensional array
                 *  5.  float [ , , ] array1 - defines a 3 dimesion array
                 *  6.  Multi-Dimensional Arrays are Simpler when compared to Jagged Arrays.
                 *  7.  The second, third dimension can only be arrays.  Can be any collection with Jagged Arrays
                 *
                 * Jagged Arrays.
                 *  1. Concept - You can put an Array into an Array
                 *  2. float [ ][ ] array1  - defines this as an array of arrays of floats.
                 *  3. float [ ][ ][ ] array1 - defines this as an array of arrays or arrays
                 *  4. float[ ][ ] array1 = new array1[4][]   -  you always have to set the first elment - says we will store 4 sets of arrays
                 *  5. Inner arrays (which is defined by the second element) do not have to be the same length, which is why they are called jagged.
                 *  6. The inner array can be any collections (.i.e. can be a List<int>)
                 *
                 *
                 */
                Console.Clear();
                Console.WriteLine(" Store data in and retrieve data from Collections  ");
                Console.WriteLine("     Store and retrieve data by using dictionaries, arrays, lists, sets,  ");
                Console.WriteLine("     and queues; hoose a collection type; initialize a collection; add    ");
                Console.WriteLine("     and remove items from a collection; use typed versus non-typed  ");
                Console.WriteLine("     collections; implement custom collections; implement collection interfaces. \n ");
                Console.WriteLine(" 0.  Print Obect Array  ");
                Console.WriteLine(" 1.  Print Generic List   ");
                Console.WriteLine(" 2.  Print Generic List Two   ");
                Console.WriteLine(" 3.  Print Generic List Three ");
                Console.WriteLine(" 4.  Class return List in Descending Order");
                Console.WriteLine(" 5.  Website ");
                Console.WriteLine(" 6.  Take Verb");
                Console.WriteLine(" 7.  Sort Ascendingz-Descending ");
                Console.WriteLine(" 8.  Dictionary and other Iterations");
                Console.WriteLine(" 9.  Quit            \n ");
                Console.Write(" Enter Number to execute Routine ");


                int   selection;
                int[] J = { 1, 2, 3 };
                selection = Common.readInt("Enter Number to Execute Routine : ", 0, 9);
                switch (selection)
                {
                case 0:
                    PrintObjectArray(new { i = J[2] });
                    break;

                case 1: PrintGenericList();
                    break;

                case 2: PrintGenericList2();
                    break;

                case 3: new PrintGenericList3().Print();
                    break;

                case 4: List <CommonCollections.Cat> threecats = CommonCollections.GetSomeCats(3);
                    Console.WriteLine(" Listed in Descending Order ");
                    Console.WriteLine(" Example of a Class returning three Cats");
                    foreach (CommonCollections.Cat c in threecats)
                    {
                        Console.WriteLine(SortingExamples.PrintCats(c));
                    }
                    Console.ReadKey();
                    //
                    // Returning Full List
                    //
                    List <CommonCollections.Cat> dbcats = CommonCollections.GetAllCats();
                    Console.WriteLine(" Example of a Class returning a Full List");
                    foreach (CommonCollections.Cat c in dbcats)
                    {
                        Console.WriteLine(SortingExamples.PrintCats(c));
                    }
                    Console.ReadKey();
                    break;

                case 5:
                    // Arrays_Collections();
                    Using_Collections();
                    break;

                case 6:
                    Test_To_take.TopThree();
                    break;

                case 7:
                    SortingExamples.Sort_Ascending_Descending();
                    SortingExamples.Sort_A_Class();
                    break;

                case 8: IterationStatements.Menu();
                    break;

                case 9: x = 9;
                    break;

                default: Console.WriteLine(" Invalid Number");
                    break;
                }
            } while (x < 9);  // end do
        }  // end Collections Menu()