static void Main(string[] args) { Hund h = new Hund() { Navn = "Oskar" }; h.Gem(); Ubåd u = new Ubåd() { Tubine = 2, Nummer = 596 }; u.Gem(); IDbFunktioner[] dimser = new IDbFunktioner[5]; dimser[0] = new Hund() { Navn = "Fido" }; dimser[1] = new Ubåd() { Tubine = 3.001, Nummer = 443 }; dimser[2] = new Ubåd() { Tubine = -.993, Nummer = 21 }; dimser[3] = new Hund() { Navn = "Otto" }; dimser[4] = new Hund() { Navn = "Walther" }; foreach (var item in dimser) { item.Gem(); } }
static void Main(string[] args) { List <Hund> hundLista = new List <Hund>(); bool isRunning = true; while (isRunning) { Console.WriteLine("[1] Lägg till en ny Hund" + "\n[2] Visa alla hundar" + "\n[3] Avsluta programmet"); Int32.TryParse(Console.ReadLine(), out int menyval); switch (menyval) { case 1: Console.WriteLine("Var god skriv hundens namn:"); string namn = Console.ReadLine(); Console.WriteLine("Var god skriv vilken hundras den har:"); string hundras = Console.ReadLine(); Console.WriteLine("Var god skriv hur gammal den är:"); Int32.TryParse(Console.ReadLine(), out int ålder); Console.WriteLine("Tack! Hunden är sparad i hundlistan!"); Hund nyHund = new Hund(namn, hundras, ålder); hundLista.Add(nyHund); break; case 2: foreach (Hund vovve in hundLista) { Console.WriteLine(vovve.Namn + " -" + vovve.Hundras + " (" + vovve.Ålder + " år)"); } break; case 3: isRunning = false; break; default: break; } } }
static void Main(string[] args) { Hund h = new Hund { Navn = "Henning" }; Kat k = new Kat { Navn = "Kathrine" }; h.SigNoget(); k.SigNoget(); for (int i = 0; i < 20; i++) { Dyr.TilfældigtDyr().SigNoget(); } Console.ReadKey(); }
public static void Main() { Tier einTier = new Hund(); einTier.GibLaut(); // virtual dispatch (virtual table = v-table) Console.WriteLine("==============================="); // Tier tier = new Tier(); <- nicht möglich, da man keine abstrakte Klasse instanziieren kann List <Tier> tiere = new List <Tier>(); tiere.Add(new Hund()); tiere.Add(new Hund()); tiere.Add(new Katze()); tiere.Add(new Hund()); foreach (Tier tier in tiere) { tier.GibLaut(); // virtual dispatch (virtual table = v-table) } // ohne Vererbungshierarchie List <Hund> hunde = new List <Hund>(); List <Katze> katzen = new List <Katze>(); hunde.Add(new Hund()); hunde.Add(new Hund()); katzen.Add(new Katze()); foreach (Hund hund in hunde) { hund.GibLaut(); // kein virtual dispatch } foreach (Katze katze in katzen) { katze.GibLaut(); // kein virtual dispatch } }
static void Main(string[] args) { A a = new A(); a.MetodeA(); B b = new B(); A aa = new C(); b.MetodeA(); b.MetodeB(); //B bb = (B)aa; // Typecasting to access the methods of B A[] array = new A[3]; array[0] = new A(); array[1] = new B(); array[2] = new C(); Hund h = new Hund(); //Console.WriteLine(h.ToString); foreach (var item in array) { } }
static void Main(string[] args) { Hund h1 = new Hund(); Hund h2 = new Hund(); Kat k1 = new Kat(); Kat k2 = new Kat(); Dyr d1 = TilfældigtDyr(); h1.SigNoget(); k1.SigNoget(); h2.SigNoget(); k2.SigNoget(); d1.SigNoget(); Dyr[] dyr = new Dyr[20]; for (int i = 0; i < 20; i++) { dyr[i] = Dyr.TilfældigtDyr(); } foreach (var item in dyr) { item.SigNoget(); } }
static void Main(string[] args) { Hund h = new Hund(); h.Navn = "Fido"; h.SkalTisse += (s, e) => { Hund hund = s as Hund; Console.WriteLine(hund.Navn + " skal Tisse"); }; h.SkalTisse += (s, e) => { Console.WriteLine("Jeg vil UUUDDD "); }; h.SkalTisse2 += (s, e) => { Hund hund = s as Hund; Console.WriteLine(hund.Navn + " skal Tisse på niveau " + e.Niveau); }; h.Test(); if (System.Diagnostics.Debugger.IsAttached) { System.Console.Write("Press any key to continue . . . "); System.Console.ReadKey(); } return; #region test /* * System.Timers.Timer tt = new System.Timers.Timer(); * tt.Enabled = true; * tt.Interval = 1000; * tt.Elapsed += (s, e) => { Console.WriteLine("Tick"); }; * * * do { } while (true); * * //Console.ReadKey(); * * * System.IO.FileSystemWatcher fw = new System.IO.FileSystemWatcher(@"c:\temp"); * fw.EnableRaisingEvents = true; * * fw.Created += Fw_Created; * fw.Deleted += delegate (object sender, System.IO.FileSystemEventArgs e) { Console.WriteLine("Fil slettet"); }; * * fw.Changed += (s, e) => { Console.WriteLine("Fil ændret"); }; * * * * MinDelegate m1 = Test1; // new MinDelegate(Test1); * // kan afvikles på begge måde * Test1(); * m1.Invoke(); * m1(); * * //MinDelegate2 m2 = new MinDelegate2(Test2); * MinDelegate2 m2 = Test2; // syntakssukker * bool res1 = Test2(3); * bool res2 = m2.Invoke(233); * res2 = m2(45); // syntakssukker * * MinDelegate3 m3 = Test3; * double g = m3(3,6); * * MinDelegate4 m4 = Console.WriteLine; * m4 += Test4; * m4("Hfjkld"); * * Action p1 = Test1; * Action<string> p2 = Console.WriteLine; * Action<string, object> p3 = Console.Write; * * Func<int, int, int> p4 = Test5; * Func<double, double, double> p5 = Math.Atan2; // Find noget, der passer * * Action<string> p6 = Test4; * p6 += Console.WriteLine; * p6 += delegate (string txt) { Console.WriteLine("I min anonyme funktion" + txt); }; * p6 += delegate (string t) { System.IO.File.WriteAllText(@"c:\temp\t.txt", t); }; * p6 += (string t) => { System.IO.File.WriteAllText(@"c:\temp\t2.txt", t); }; * p6 += t => { System.IO.File.WriteAllText(@"c:\temp\t3.txt", t); }; * p6("ffgg"); * * Action<string, string> p7 = (p, c) => { System.IO.File.WriteAllText(p, c); }; * p7(@"c:\temp\t4.txt", "flkgæsjglksgjlkfæjgæls"); * * * int[] a = { 2, 3, 76, 45, 7, 5, 77 }; * var b = Array.FindAll(a, type => type < 10); */ #endregion }
public void TilføjHund(Hund h) // Nu er den lavet type stærk { lst.Add(h); }
//private static double Momspct = 0.25; static void Main(string[] args) { // så kan man spørge på argumenter til programmet if (args.Length > 0) { foreach (var item in args) { System.Console.WriteLine(item); } ; } ; // Så kan man hente i konfigurationsfilen //modul+add+reference: system.coonfiguration string m = System.Configuration.ConfigurationManager.AppSettings["moms"]; double moms = 0; if (m != null) { moms = Convert.ToDouble(m); } //Eller bruge program properties + settings. //kan bruges som en mini dattabase. string x = Module11_Collections.Properties.Settings.Default.Xpos; System.Collections.ArrayList lst1 = new System.Collections.ArrayList(); lst1.Add(1); lst1.Add(2); lst1.Remove(1); System.Collections.ArrayList lst2 = new System.Collections.ArrayList(); lst2.Add(new Hund() { Navn = "a" }); lst2.Add(new Hund() { Navn = "b" }); lst2.Remove(1); System.Collections.Stack lst3 = new System.Collections.Stack(); lst3.Push(1); lst3.Push(2); lst3.Push(133); System.Collections.Queue lst4 = new System.Collections.Queue(); lst4.Enqueue(new Hund() { Navn = "A" }); lst4.Enqueue(new Hund() { Navn = "B" }); lst4.Enqueue(new Hund() { Navn = "C" }); Hund h = (Hund)lst4.Dequeue(); System.Collections.Hashtable lst5 = new System.Collections.Hashtable(); lst5.Add("a", "a"); lst5.Add("b", "a"); lst5.Add("c", "a"); string r = lst5["b"].ToString(); Kennel kennel = new Kennel(); kennel.TilføjHund(h); ////////////////// System.Collections.Generic.List <Hund> lst6 = new System.Collections.Generic.List <Hund>(); lst6.Add(new Hund() { Navn = "a" }); lst6.Add(new Hund() { Navn = "b" }); Hund hh = lst6[0]; Queue <int> lst7 = new Queue <int>(); lst7.Enqueue(5); int ii = lst7.Dequeue(); Dictionary <int, Hund> lst8 = new Dictionary <int, Hund>(); lst8.Add(4, new Hund() { Navn = "b" }); lst8.Add(22, new Hund() { Navn = "g" }); Hund hhh = lst8[4]; List <string> lst9 = new List <string>(); lst9.Add("A1"); lst9.Add("B1"); lst9.Add("E1"); lst9.Add("C1"); foreach (var item in lst9) { System.Console.WriteLine(item); } for (int i = 0; i < lst9.Count; i++) { System.Console.WriteLine(lst9[i].ToString()); } //Test<MinType> t1 = new Test<MinType>(); Kennel2 k2 = new Kennel2(); //k2.Add(new Hund); //k2.Add(Hund ); if (System.Diagnostics.Debugger.IsAttached) { System.Console.Write("Press any key to continue . . . "); System.Console.ReadKey(); } }
public void istrueTEst() { var hund = new Hund("Marko"); Assert.IsTrue(hund.Name == "Marko"); }
public void HundName() { var hund = new Hund("Marko"); Assert.AreEqual("Marko", hund.Name); }
// ref: Werttyp änderbar // out: zusätzlicher Rückgabewert static void Adeln(ref Hund hund) { hund.Name = hund.Name + " von Knochenbrug"; }