After learning how to use the functions of C#, a good challenge for yourself is to set a task to complete using the key items of what you know. For myself, I chose to put together a generator to fill in pieces to a bracket for a competition. Because of simplicity, the example I will use is Greek Week, which involves competitions between sororities and fraternities. There will be 5 events, and 5 teams. Three of the events will require a bracket set-up as pictured below:
So there will be one team that gets a bye for the first round of play. In order to deal with this, we will use 2 separate lists. One array will hold the teams to be placed in the brackets, while the other will keep track of what teams have had a bye already. No team shall have more than one bye for the tournament.
Regarding the final two events which do not require a bracket, they will be performed by teams in random order for time, or judging. This is simple enough, as we will select a random order 1 through 5.
The code for the Bracket of event 1 is shown below:
What happens here is teams are randomly selected into the brackets, and the final team to be picked is placed into the bye list. From this point onward, the team which was assigned the Bye will not be able to get another bracket in which this happens. To account for this, for each event beyond, the teams that cannot get another bye will be removed from the event's list of teams, and placed into the bracket. Thus, each event beyond here will automatically have a team which had a Bye to be in a played game immediately.
The ordered events at the end will contain a very basic structure, and the code is shown below:
This is simple enough, it simply goes through the array until it is exhausted.
Our output will look like this (granted it will be a new outcome each time:
As you can see, building a program in C# is relatively simple, yet efficient. This could easily be expanded to be a much larger scale, for example, possibly a tournament of 15, or 31, or even more. The efficiency of C# as a language enables us to build great programs quickly and relatively painlessly.