Course Content
C# Beyond Basics
C# Beyond Basics
Practicing 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.
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"]);
}
}
}
Everything was clear?
Section 1. Chapter 5
Course Content
C# Beyond Basics
C# Beyond Basics
Practicing 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.
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"]);
}
}
}
Everything was clear?
Section 1. Chapter 5