Esempio n. 1
0
        /// <summary>
        ///	Make a Dictionary with Star Wars persons as keys.
        /// each get a true/false if they are jedi/not jedi as value.
        /// Iterate over them and show jedi status.
        /// </summary>

        public void DictionaryMethod()
        {
            string outputvalue = "";
            Dictionary <string, bool> chars = new Dictionary <string, bool>();

            chars.Add("Luke", true);
            chars.Add("Chewie", false);
            chars.Add("Han Solo", false);
            chars.Add("Yoda", true);
            chars.Add("Leia", false);
            foreach (KeyValuePair <string, bool> kvp in chars)
            {
                if (kvp.Value)
                {
                    outputvalue += $"{kvp.Key} is a jedi.\n";
                }
                else
                {
                    outputvalue += $"{kvp.Key} is not a jedi.\n";
                }
            }
            View.Windows.ReturnWindow rw = new View.Windows.ReturnWindow();
            rw.MsgTxt.Text = outputvalue;
            rw.Show();
        }
Esempio n. 2
0
        //Make a Stack.
        //Add some Star Wars-movies to it.
        //Empty the Stack.
        public void StackCreator()
        {
            string         outputvalue = "";
            Stack <string> movies      = new Stack <string>();

            movies.Push("The Empire Strikes Back");
            movies.Push("A New Hope");
            movies.Push("The Phantom Menace");

            do
            {
                outputvalue += $"Movie removed: {movies.Pop()}\n";
            }while (movies.Count > 0);
            outputvalue += $"\nThe Stack now has {movies.Count} entries";
            View.Windows.ReturnWindow rw = new View.Windows.ReturnWindow();
            rw.MsgTxt.Text = outputvalue;
            rw.Show();
        }
Esempio n. 3
0
        public void LinkedListMethod()
        {
            string[] mnths =
            { "Februar", "Marts", "Maj", "Juni", "Juli", "August", "Oktober", "November" };
            LinkedList <string> monthsList = new LinkedList <string>(mnths);
            string outputValue             = "Start-LinkedList:\n";

            foreach (string s in monthsList)
            {
                outputValue += s + "  ";
            }

            monthsList.AddFirst("Januar");
            outputValue += "\n\nAdded Januar:\n";
            foreach (string s in monthsList)
            {
                outputValue += s + "  ";
            }

            monthsList.AddBefore(monthsList.Find("Maj"), "April");
            outputValue += "\n\nAdded April:\n";
            foreach (string s in monthsList)
            {
                outputValue += s + "  ";
            }

            monthsList.AddAfter(monthsList.Find("August"), "September");
            outputValue += "\n\nAdded September:\n";
            foreach (string s in monthsList)
            {
                outputValue += s + "  ";
            }

            monthsList.AddLast("December");
            outputValue += "\n\nAdded December:\n";
            foreach (string s in monthsList)
            {
                outputValue += s + "  ";
            }

            View.Windows.ReturnWindow rw = new View.Windows.ReturnWindow();
            rw.MsgTxt.Text = outputValue;
            rw.Show();
        }