It is inevitable at some point in coding that you will come across the need to handle errors and exceptions. You can take care of most predictable scenarios but checking variables and such. However users will always find ways to work with your programs in ways you never intended or saw coming. And in doing this they will introduce errors that you will need to handle. That’s where try/catch/finally comes into play. I made a simple text file reader to demonstrate the ability to throw custom errors based off the ReadAllText() method. This gives a small glimpse into catching and handling exceptions.
I have to admit that since figuring out how Lambda expressions work I’ve been using them quite a bit. This and becoming a fan of ArrayList and generic collections over arrays. But for this program I wanted concentrate on the usage of lambda expressions being used with event arguments. The goal of the game is to click on each target before the timer runs out. If you get 4 batches of hits total you progress to the next level. In later versions I’ll implement the ability to select the player level manually.
Delegates and events. This was a hard concept for me to grasp when I first starting studying this. Actually let me be more specific. The Delegates part wasn’t that bad. Understanding how Events work, how they’re constructed, triggered, etc… Specifically custom events as you will see from the source. For example double-clicking on the Form_Load event to have Visual Studio create the event for you automatically is easy. But, for example, constructing menu clicks to custom event handlers to custom methods that fire off in a different class was a hard concept to grasp. However once I FINALLY understood all of this everything started falling into place. And I do use what I’ve learned a log in my other programs. If done right it just makes for cleaner, more understanding code.
Also if you notice I start using the ArrayList collection and you will see other collection methods moving forward as I’m learning about them. Don’t get me wrong Arrays are fun and have their place. But other collection methods can be used also.
I wanted to make a change to the Temperature Conversion program I did earlier to demonstrate how Structs work. Structs are a value data type. Unlike a class which is a reference data type. One of the main things I noticed is you don’t need to create an instance to use a struct. However they are limiting which may or may not be good depending on what you want to accomplish.
This simple game demonstrates more class / object inheritance along with showing how abstract and sealed classes work together. Along with my previous programs on using arrays to store data. You will notice from the class designer picture that the RoundPopper, StringPopper, and RectanglePopper classes all derive from the Popper abstract class. Also the OvalPopper derives from the RoundPopper classes while deriving from the OvalPopper class. I know more complicated that it needs to be. I just did it this way to show the inheritance concepts.