Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Utmaning: Ordböcker | Datastrukturer och Filhantering
C# Bortom Grunderna

bookUtmaning: Ordböcker

Fyll i luckorna för att deklarera ett nytt dictionary kallat book, samt för att lägga till och skriva ut data. Använd implicit deklaration för att skapa dictionaryn.

index.cs

index.cs

copy
123456789101112131415161718192021222324
using 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: " + ___); } } }
  1. Använd metoden Add för att lägga till data i dictionaryn.
  2. Du kan komma åt värden från dictionaryn med hjälp av syntaxen dictionaryName[keyName].
index.cs

index.cs

copy
123456789101112131415161718192021222324
using 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 allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 5

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you show me an example of how to declare and add data to the dictionary?

What does "implicit declaration" mean in this context?

How do I output the data from the dictionary?

Awesome!

Completion rate improved to 2.04

bookUtmaning: Ordböcker

Svep för att visa menyn

Fyll i luckorna för att deklarera ett nytt dictionary kallat book, samt för att lägga till och skriva ut data. Använd implicit deklaration för att skapa dictionaryn.

index.cs

index.cs

copy
123456789101112131415161718192021222324
using 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: " + ___); } } }
  1. Använd metoden Add för att lägga till data i dictionaryn.
  2. Du kan komma åt värden från dictionaryn med hjälp av syntaxen dictionaryName[keyName].
index.cs

index.cs

copy
123456789101112131415161718192021222324
using 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 allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 5
some-alt