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

Praticando DicionáriosPraticando Dicionários

Preencha as lacunas para declarar um novo dicionário chamado book, assim como para adicionar e exibir dados. Use a declaração implícita para criar o dicionário.

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

Tudo estava claro?

Seção 1. Capítulo 5
course content

Conteúdo do Curso

C# Beyond Basics

Praticando DicionáriosPraticando Dicionários

Preencha as lacunas para declarar um novo dicionário chamado book, assim como para adicionar e exibir dados. Use a declaração implícita para criar o dicionário.

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

Tudo estava claro?

Seção 1. Capítulo 5
some-alt