Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Opgave med arv - exception");
            try
            {
                StockItem s = new StockItem(-1);
            }
            catch (StockItemException ex)
            {
                Console.WriteLine("StockItem Error : " + ex.Message);
            }
            catch (Exception)
            {
                Console.WriteLine("General Error");
            }

            Console.WriteLine();
            Console.WriteLine("Opgave med arv - udvid System.Random");
            UdvidetRandom r = new UdvidetRandom();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(r.NextBool()); // true eller false
            }

            Console.WriteLine();
            Console.WriteLine("Opgave med arv - simpel");
            Person p1 = new Person();

            p1.Fornavn   = "Nicholas";
            p1.Efternavn = "Schott";

            Person p2 = new Person()
            {
                Fornavn = "Christoffer", Efternavn = "Schott"
            };

            Console.WriteLine("Første person er " + p1.FuldtNavn());
            Console.WriteLine("Anden person er  " + p2.FuldtNavn());

            Elev e1 = new Elev()
            {
                Fornavn = "Elev1", Efternavn = "ElevEfternavn1", Klasselokale = "Astralis"
            };
            Instruktør i1 = new Instruktør()
            {
                Fornavn = "Instruktør1", Efternavn = "InsturktørEfternavn1", NøgleId = 1
            };

            Console.WriteLine("Første elev er   " + e1.FuldtNavn());
            Console.WriteLine("Første instruktør er " + i1.FuldtNavn());

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            UdvidetRandom r = new UdvidetRandom();

            Console.WriteLine(r.NextBool());

            Console.WriteLine(r.Next(1, 1002));

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            UdvidetRandom r = new UdvidetRandom();

            Console.WriteLine(r.NextBool());



            UdvidetRandom udvidetRandom = new UdvidetRandom();

            // Keep console window open when using the debugger (F5)
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey();
            }
        }
Esempio n. 4
0
        public static Dyr TilfældigtDyr()
        {
            // Læs fil med dyrenavne.
            string sti = @"x:\dyrenavne.txt";

            string[] dyrenavne = File.ReadAllLines(sti);

            if (r.NextBool())
            {
                return(new Hund()
                {
                    Navn = dyrenavne[r.Next(0, dyrenavne.Length)]
                });
            }
            else
            {
                return(new Kat()
                {
                    Navn = dyrenavne[r.Next(0, dyrenavne.Length)]
                });
            }
        }