Udfordring: Ordbøger
Udfyld felterne for at erklære et nyt dictionary kaldet book
, samt for at tilføje og udskrive data. Brug implicit erklæring til at oprette dictionary'en.
index.cs
123456789101112131415161718192021222324using System; using System.Collections.Generic; namespace ConsoleApp { class Program { static void Main(string[] args) { // Declaring a new empty dictionary ___ ___ = new Dictionary<string, string>(); // Adding data to the dictionary ___("name", "The Hobbit"); ___("author", "J. R. R. Tolkien"); ___("publication date", "21 September 1937"); // Outputting data Console.WriteLine("Book Name: " + ___); Console.WriteLine("Author: " + ___); Console.WriteLine("Publication Date: " + ___); } } }
- Brug
Add
-metoden til at tilføje data til dictionary'en. - Du kan tilgå værdier fra dictionary'en ved at bruge syntaksen
dictionaryName[keyName]
.
index.cs
123456789101112131415161718192021222324using System; using System.Collections.Generic; namespace ConsoleApp { class Program { static void Main(string[] args) { // Declaring a new empty dictionary var book = new Dictionary<string, string>(); // Adding data to the dictionary book.Add("name", "The Hobbit"); book.Add("author", "J. R. R. Tolkien"); book.Add("publication date", "21 September 1937"); // Outputting data Console.WriteLine("Book Name: " + book["name"]); Console.WriteLine("Author: " + book["author"]); Console.WriteLine("Publication Date: " + book["publication date"]); } } }
Var alt klart?
Tak for dine kommentarer!
Sektion 1. Kapitel 5
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 2.04
Udfordring: Ordbøger
Stryg for at vise menuen
Udfyld felterne for at erklære et nyt dictionary kaldet book
, samt for at tilføje og udskrive data. Brug implicit erklæring til at oprette dictionary'en.
index.cs
123456789101112131415161718192021222324using System; using System.Collections.Generic; namespace ConsoleApp { class Program { static void Main(string[] args) { // Declaring a new empty dictionary ___ ___ = new Dictionary<string, string>(); // Adding data to the dictionary ___("name", "The Hobbit"); ___("author", "J. R. R. Tolkien"); ___("publication date", "21 September 1937"); // Outputting data Console.WriteLine("Book Name: " + ___); Console.WriteLine("Author: " + ___); Console.WriteLine("Publication Date: " + ___); } } }
- Brug
Add
-metoden til at tilføje data til dictionary'en. - Du kan tilgå værdier fra dictionary'en ved at bruge syntaksen
dictionaryName[keyName]
.
index.cs
123456789101112131415161718192021222324using System; using System.Collections.Generic; namespace ConsoleApp { class Program { static void Main(string[] args) { // Declaring a new empty dictionary var book = new Dictionary<string, string>(); // Adding data to the dictionary book.Add("name", "The Hobbit"); book.Add("author", "J. R. R. Tolkien"); book.Add("publication date", "21 September 1937"); // Outputting data Console.WriteLine("Book Name: " + book["name"]); Console.WriteLine("Author: " + book["author"]); Console.WriteLine("Publication Date: " + book["publication date"]); } } }
Var alt klart?
Tak for dine kommentarer!
Sektion 1. Kapitel 5