A collection definition typically includes a place holder in angle brackets, often T
by convention. Such a collection is referred to as a generic type. This allows the collection user to specify what type of items to store in the collection. In the example code below we are instantiating a list of strings.
Lists in C# are collections of primitive values or instances of structs or classes. They are implemented in the base class library as List<T>
where T
is the type of the item in the list. The API exposes a rich set of methods for creating and manipulating lists.
Items can be added to and removed from lists. They grow and shrink as necessary.
var listOfStrings = new List<string>();
In this exercise you'll be writing code to keep track of a list of programming languages you want to learn on Exercism.
You have nine tasks, which will all involve dealing with lists.
To keep track of the languages you want to learn, you'll need to create a new list.
Implement the static Languages.NewList()
method that returns a new, empty list.
Languages.NewList()
// => empty list
Currently, you have a piece of paper listing the languages you want to learn: C#, Clojure and Elm.
Please implement the static Languages.GetExistingLanguages()
method to return the list.
Languages.GetExistingLanguages();
// => {"C#", "Clojure", "Elm"}
As you explore Exercism and find more interesting languages, you want to add them to your list.
Implement the static Languages.AddLanguage()
function to add a new language to the end of your list.
Languages.AddLanguage(Languages.GetExistingLanguages(), "VBA");
// => {"C#", "Clojure", "Elm", "VBA"}
Counting the languages one-by-one is inconvenient.
Implement the static Languages.CountLanguages()
method to count the number of languages on your list.
Languages.CountLanguages(Languages.GetExistingLanguages())
// => 3
Implement the static Languages.HasLanguage()
method to check if a language is present.
Languages.HasLanguage(Languages.GetExistingLanguages(), "Elm")
// => true
At some point, you realize that your list is actually ordered backwards!
Implement the static Languages.ReverseList()
method to reverse your list.
Languages.ReverseList(Languages.GetExistingLanguages())
// => {"Elm", "Clojure", "C#"}
While you love all languages, C# has a special place in your heart. As such, you're really excited about a list of languages if:
Implement the static Languages.IsExciting()
method to check if a list of languages is exciting:
Languages.IsExciting(Languages.GetExistingLanguages())
// => true
Please implement the static Languages.RemoveLanguage()
method to remove a specified language from the list.
Languages.RemoveLanguage(Languages.GetExistingLanguages(), "Clojure")
// => { "C#", "Elm" }
Please implement the static Languages.IsUnique()
method to check if any of the languages is repeated in the list.
The list of languages (i.e. the parameter) is guaranteed not to be empty when this method is called and it doesn't matter if the list is modified.
Languages.IsUnique(Languages.GetExistingLanguages())
// => true
Sign up to Exercism to learn and master C# with 62 concepts, 175 exercises, and real human mentoring, all for free.