Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Practicing Dictionaries | Additional Structures & File Handling
C# Beyond Basics

Practicing DictionariesPracticing Dictionaries

Fill in the blanks to declaring a new dictionary called book, also for adding and outputting data. Use implicit declaration for creating the dictionary.

cs

index.cs

1. We use the Add method for adding data to the dictionary.
2. We can access values from the dictionary using the dictionaryName[keyName] syntax.

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"]);
        }
    }
}   

Все було зрозуміло?

Секція 1. Розділ 5
course content

Зміст курсу

C# Beyond Basics

Practicing DictionariesPracticing Dictionaries

Fill in the blanks to declaring a new dictionary called book, also for adding and outputting data. Use implicit declaration for creating the dictionary.

cs

index.cs

1. We use the Add method for adding data to the dictionary.
2. We can access values from the dictionary using the dictionaryName[keyName] syntax.

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"]);
        }
    }
}   

Все було зрозуміло?

Секція 1. Розділ 5
some-alt