//the main method
        //a array of string values representing numbers to demonstrate the power of linq
        public static void Main()
        {
            int d1 = rectArray.GetLength(0);//initialising the rectangular array
            int d2 = rectArray.GetLength(1);//done twice for the two dimentions
            for (int ho = 0; ho < d1; ho++)//counting the first dimention of the rectangular array
            {
                for (int ve = 0; ve < d2; ve++)//reading the retangular array and populating the numbers to a rectangle
                {
                    Console.WriteLine(rectArray[ho, ve] + "\t");//writes the array to the console, the t represents special characters
                }
            }
                Console.WriteLine("Drink sizes: 1=Tea 2=Coffee 3=Hot Chocolate");//instructions for the user

                Console.Write("Please enter your selection: "); //instructions for the user
                string s = Console.ReadLine();//reads the users input
                int n = int.Parse(s);//creates int n from the input
                CostStruct CS = new CostStruct();//initialsies the struct cost from class CostStruct
                double cost = CS.cost;//makes the cost the value in the cost struct

                string i = "coffee", j = "tea";//puts strings into the values i and j
                refParam.Swap(ref i, ref j);//preforms the swap action using reference paramaters in refParam
                Console.WriteLine(" {0}, {1}", i, j);//writes the results of i and j, now switched
                switch (n)  //switch statement initalised
                {
                    case 1:
                        cost += 0.25;//switch statement case when 1 is entered, adds 0.25 to the  cost
                        break;
                    case 2:
                        cost += 0.25;//switch statement case when 2 is entered, adds itself and case 1 to cost
                        goto case 1;
                    case 3:
                        cost += 0.50;//switch statement case when 3 is entered, addis itself to case 1
                        goto case 1;
                    default:
                        Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");
                        break;//the text shown if a value other than 1, 2 or 3 is entered
                }
                if (cost != 0)//this line only runs if the previous statement was correct
                    Console.WriteLine("Please insert {0} pounds.", cost);//adds whatever value is in cost to the statement
                Console.WriteLine("Thank you.");//thanks you
                string r = "ありがとうございました!", m = "Je vous remercie!";
            //thanks you again, written in different languages
                refParam.Swap(ref r, ref m);//swaps the order of the thank you's around using ref paramaters
                Console.WriteLine("{0}, {1}", r, m);//shows you the new order

                var textNums =
            from num in LinqNums//parses the LinqNums array
            select LinqStrs[num];
            //parses the LinqStrings array and selects the equivalent values from the strings and displays them as numbers

                Console.WriteLine("Number strings:");//introduces the user to what is coming next
                foreach (var val in textNums)//for loop to print all numbers in the array
                {
                    Console.WriteLine(val);//writes the value of each number in LinqNums as a string from LinqStrings
                }
        }
Beispiel #2
0
        //a array of string values representing numbers to demonstrate the power of linq
        public static void Main()                                //the main method
        {
            int d1 = rectArray.GetLength(0);                     //initialising the rectangular array
            int d2 = rectArray.GetLength(1);                     //done twice for the two dimentions

            for (int ho = 0; ho < d1; ho++)                      //counting the first dimention of the rectangular array
            {
                for (int ve = 0; ve < d2; ve++)                  //reading the retangular array and populating the numbers to a rectangle
                {
                    Console.WriteLine(rectArray[ho, ve] + "\t"); //writes the array to the console, the t represents special characters
                }
            }
            Console.WriteLine("Drink sizes: 1=Tea 2=Coffee 3=Hot Chocolate"); //instructions for the user

            Console.Write("Please enter your selection: ");                   //instructions for the user
            string     s    = Console.ReadLine();                             //reads the users input
            int        n    = int.Parse(s);                                   //creates int n from the input
            CostStruct CS   = new CostStruct();                               //initialsies the struct cost from class CostStruct
            double     cost = CS.cost;                                        //makes the cost the value in the cost struct

            string i = "coffee", j = "tea";                                   //puts strings into the values i and j

            refParam.Swap(ref i, ref j);                                      //preforms the swap action using reference paramaters in refParam
            Console.WriteLine(" {0}, {1}", i, j);                             //writes the results of i and j, now switched
            switch (n)                                                        //switch statement initalised
            {
            case 1:
                cost += 0.25;        //switch statement case when 1 is entered, adds 0.25 to the  cost
                break;

            case 2:
                cost += 0.25;        //switch statement case when 2 is entered, adds itself and case 1 to cost
                goto case 1;

            case 3:
                cost += 0.50;        //switch statement case when 3 is entered, addis itself to case 1
                goto case 1;

            default:
                Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");
                break;                                                //the text shown if a value other than 1, 2 or 3 is entered
            }
            if (cost != 0)                                            //this line only runs if the previous statement was correct
            {
                Console.WriteLine("Please insert {0} pounds.", cost); //adds whatever value is in cost to the statement
            }
            Console.WriteLine("Thank you.");                          //thanks you
            string r = "ありがとうございました!", m = "Je vous remercie!";

            //thanks you again, written in different languages
            refParam.Swap(ref r, ref m);         //swaps the order of the thank you's around using ref paramaters
            Console.WriteLine("{0}, {1}", r, m); //shows you the new order

            var textNums =
                from num in LinqNums//parses the LinqNums array
                select LinqStrs[num];

            //parses the LinqStrings array and selects the equivalent values from the strings and displays them as numbers

            Console.WriteLine("Number strings:"); //introduces the user to what is coming next
            foreach (var val in textNums)         //for loop to print all numbers in the array
            {
                Console.WriteLine(val);           //writes the value of each number in LinqNums as a string from LinqStrings
            }
        }