Cursos /
C# Beyond Basics
Praticando 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.
index.cs
1. We use the
2. We can access values from the dictionary using 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
Conteúdo do Curso
C# Beyond Basics
2. Estruturas & Enumeradores
C# Beyond Basics
Praticando 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.
index.cs
1. We use the
2. We can access values from the dictionary using 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