0% found this document useful (0 votes)
30 views

Collection Exercises

This document outlines exercises for working with arrays, lists, and dictionaries in C#. It includes declaring and initializing each data type, adding and removing values, and looping through to print out or access values. Exercises cover basic operations like declaring and populating an array with days of the week, adding students to a list and removing one, and creating a dictionary with color names and hex codes then looking up and removing values.

Uploaded by

Jude Nelson
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Collection Exercises

This document outlines exercises for working with arrays, lists, and dictionaries in C#. It includes declaring and initializing each data type, adding and removing values, and looping through to print out or access values. Exercises cover basic operations like declaring and populating an array with days of the week, adding students to a list and removing one, and creating a dictionary with color names and hex codes then looking up and removing values.

Uploaded by

Jude Nelson
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C# Exercises

Arrays
1. Arrays

1.1 Exercise: Declare an array

Declare an array called days, set it to length 7

1.2 Exercise: Read and write array values

Set each value of the array to a day of the week.

1.3 Exercise: Loop through the array

Print out all the days of the week

3. Lists
2.1 Exercise: Declare a list

Declare a list called Students

2.2 Exercise: Read and write list values

Write the name of 5 students in your class to the list

2.3 Exercise: Remove an item from the list

Remove one of the names

2.4 Exercise: Remove an item from the list another way

Use a different method to remove another student

2.5 Exercise: Loop through the list

Print out the remaining students


3. Dictionaries
3.1 Exercise: Declare a dictionary

Declare a dictionary called WebColours, with key and value both string

3.2 Exercise: Read and write dictionary values

Add 6 hexadecimal colours and their descriptions to the dictionary

3.3 Exercise: Remove an item from the dictionary using the value

3.4 Exercise: Loop through the dictionary and print out a list of colours and their codes

3.5 Exercise: Output the colour description for a colour code

3.6 Exercise: Output the colour code for a colour description

3.7 Exercise: Write whether or not dictionary contains a colour

3.8 Exercise: Delete last key value pair

You might also like