Utfordring: Ordbøker
Fyll ut de tomme feltene for å erklære et nytt dictionary kalt book
, samt for å legge til og vise data. Bruk implisitt deklarasjon for å opprette dictionaryen.
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: " + ___); } } }
- Bruk
Add
-metoden for å legge til data i dictionaryen. - Du kan få tilgang til verdier fra dictionaryen ved å bruke 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"]); } } }
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 5
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 2.04
Utfordring: Ordbøker
Sveip for å vise menyen
Fyll ut de tomme feltene for å erklære et nytt dictionary kalt book
, samt for å legge til og vise data. Bruk implisitt deklarasjon for å opprette dictionaryen.
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: " + ___); } } }
- Bruk
Add
-metoden for å legge til data i dictionaryen. - Du kan få tilgang til verdier fra dictionaryen ved å bruke 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"]); } } }
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 5