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

List generic collection in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with List Generic Collection in C#
📖 Scenario: You are building a simple contact list application to store names of friends. You will use a List<string> to keep track of the names.
🎯 Goal: Create and manage a List<string> to add, check, and display friend names.
📋 What You'll Learn
Create a List of strings called friends with initial names
Add a new friend name to the list
Check if a specific friend name exists in the list
Display the total number of friends in the list
💡 Why This Matters
🌍 Real World
Lists are used in many applications to store collections of items like contacts, tasks, or products.
💼 Career
Understanding List collections is essential for software development jobs that involve data management and user data handling.
Progress0 / 4 steps
1
Create the initial List of friends
Create a List<string> called friends and initialize it with these exact names: "Alice", "Bob", "Charlie".
C Sharp (C#)
Need a hint?

Use the List<string> constructor with curly braces to add initial names.

2
Add a new friend to the list
Add the friend name "Diana" to the existing friends list using the Add method.
C Sharp (C#)
Need a hint?

Use friends.Add("Diana") to add the new name.

3
Check if a friend exists in the list
Create a boolean variable called hasBob that checks if the name "Bob" exists in the friends list using the Contains method.
C Sharp (C#)
Need a hint?

Use bool hasBob = friends.Contains("Bob") to check presence.

4
Get the total number of friends
Create an integer variable called totalFriends and set it to the number of items in the friends list using the Count property.
C Sharp (C#)
Need a hint?

Use friends.Count to get the number of items.