0
0
C Sharp (C#)programming~15 mins

Explicit value assignment in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Explicit Value Assignment in C#
📖 Scenario: Imagine you are organizing a small library system. You want to assign specific ID numbers to some books so you can find them easily later.
🎯 Goal: You will create a dictionary to store book titles with their explicit ID numbers, then print the dictionary to see the assignments.
📋 What You'll Learn
Create a dictionary called bookIds with exact book titles as keys and their explicit ID numbers as values.
Create a variable called newBookId and assign it the value 105.
Add a new book with the title "The Hobbit" and the ID stored in newBookId to the dictionary.
Print the bookIds dictionary to show all book titles and their IDs.
💡 Why This Matters
🌍 Real World
Assigning explicit IDs to items like books helps organize and find them quickly in real systems like libraries or inventory management.
💼 Career
Understanding explicit value assignment and dictionary usage is important for software developers working with data storage, lookup tables, and configuration settings.
Progress0 / 4 steps
1
Create the initial dictionary with explicit values
Create a dictionary called bookIds with these exact entries: "1984": 101, "Brave New World": 102, "Fahrenheit 451": 103.
C Sharp (C#)
Need a hint?

Use new Dictionary<string, int> { {"key", value}, ... } to create the dictionary with explicit values.

2
Add a new explicit value variable
Create an integer variable called newBookId and assign it the value 105.
C Sharp (C#)
Need a hint?

Use int newBookId = 105; to assign the explicit value.

3
Add a new book with explicit ID to the dictionary
Add a new entry to the bookIds dictionary with the key "The Hobbit" and the value from the variable newBookId.
C Sharp (C#)
Need a hint?

Use bookIds["The Hobbit"] = newBookId; to add the new entry.

4
Print the dictionary to show all book IDs
Use a foreach loop with variables title and id to iterate over bookIds. Inside the loop, print each book title and its ID in the format: "{title}: {id}".
C Sharp (C#)
Need a hint?

Use foreach (var kvp in bookIds) and Console.WriteLine($"{kvp.Key}: {kvp.Value}") to print each entry.