Tag Archives: c-sharp

Binary Search Trees (BSTs) in C#

A Binary Search Tree (also known as a BST) is a data structure that contains ordered nodes. Each node contains an element, a left node and a right node. The nodes on the left are all nodes that contain values lower than the element and the nodes on the right contain values higher than the [...]

Posted in C# | Also tagged , , , , , , , , , , , , , | 3 Comments

Operator overloading in C#

C# allows you to overload certain operators. The figure below shows a table of overloadable operators. Suppose there is a BankAccount class which contains a Number property and a Balance property. The + (addition) operator can be overloaded to combine two BankAccount instances and to return a new BankAccount instance with the combined balances. This [...]

Posted in C# | Also tagged , , , , , , , , | Leave a comment

State design pattern in C#

The state pattern is a software design pattern to represent the state of an object. It allows an object to alter its behavior when its state changes. It shows a similarity to the strategy pattern.

Posted in C# | Also tagged , , , , , , , , , , , , | Leave a comment

Detecting keyboard input in XNA

Keyboard input is essential in most games. The user might use it for moving a character, mario style enemy killing and many other things. XNA supports so called keyboard states to detect keyboard input.

Posted in C# | Also tagged , , , , , , , , , | Leave a comment

Parsing XML in C#

This example parses an XML file with a collection of books into a DOM tree using a console application.

Posted in C# | Also tagged , , , , , , , | 1 Comment

Quicksort algorithm in C#

Quicksort is a divide and conquer sorting algorithm. This example uses the quicksort algorithm to sort an array of string elements.

Posted in C# | Also tagged , , , , , , | 13 Comments

Constructor overloading in C#

C# allows you to reuse existing constructors when defining new constructors.

Posted in C# | Also tagged , , , | Leave a comment

Creating the World, View and Projection matrices in XNA

The World, Projection and View matrices are used in XNA to project your 3D world on your 2D computer screen. The theory behind 3D projection can be found here.

Posted in C# | Also tagged , , , , , , , , , , , , | Leave a comment

Generating a random color in C#

Always wanted to have your own random color generator in C#? This snippet shows you how to do it.

Posted in C# | Also tagged , , , , , , , , | 1 Comment

Framerate GameComponent to calculate the frame rate (XNA Framework)

Microsoft XNA can be used to develop computer games. This code snippet contains a so called GameComponent written in C#. The GameComponent is called Framerate and it simply calculates the frame rate of the game at each Update cycle.

Posted in C# | Also tagged , , , , , , , | Leave a comment