Try our mobile site!

Recursive Backtracking

By Daniel Taylor on June 23, 2012

Consider a recursive function that makes multiple recursive calls. Each node in the tree of function calls is a tree itself requiring multiple recursive calls. As you progress down the tree, the number of recursive calls increases dramatically. These exhaustive recursion algorithms are often quite expensive and that is not favorable when looking to find a solution quickly and optimally. So instead of looking through every possible option, what if we stopped once we found a solution. This can be achieved through a method called backtracking. Backtracking is used when there is not enough information to advance directly toward the solution, but can be solved by tracing a path from the root of the tree to the bottom of the tree.

Intro to Recursion

By Daniel Taylor on June 19, 2012

Recursion is a technique to define an operation in terms of itself. Functional recursion is a specific type of recursion in which a function is specified in terms of itself. Recursion is an incredibly powerful tool that can be quite mysterious. Until you can wrap your head around this paradigm, you will have to take a leap of faith and just trust that recursion works.

Enums

By Daniel Taylor on August 27, 2011

Enums are strongly typed constants. They are types that allow you to group constants together as well as assign an index to each element in the enum. Enums often describe some kind of state.

Constants and Readonly Fields

By Daniel Taylor on August 26, 2011

There will inevitably be times when you have fields that you don't want to be edited after they are set. For example, you wouldn't want the client to be able to change the mathematical value of pi. You might not want the server ip address to be changed either. In these cases, constants or readonly fields are the solution. Both accomplish the same basic task, but each one excels in certain situations.

Structs

By Daniel Taylor on August 23, 2011

You already have a good understanding about how classes work, but you may not be aware of their closely related counterpart, structs. Like a class, structs can contain fields, constructors, and methods, but there are two main differences. Structs are forcibly sealed, therefore, structs cannot be inherited from. The most important difference is found in how structs are passed around in your program. While a class is a reference type, a struct is a value type. Reference types hold a reference to an object in memory while value types hold thier value in memory. Because structs are value types, they don't incur the overhead associated with reference types.

Indexers

By Daniel Taylor on July 28, 2011

Indexers are super simple. They allow you to treat an object as if it were an array with very little additional code.

The indexer requires an index as an argument. This parameter can be any object, but is most commonly an integer. The name of the indexer is always the this keyword because the indexer operates on the class itself. The definition of an indexer is very similar to that of a property.

Multidimensional Arrays

By Daniel Taylor on July 19, 2011

In the last tutorial, you learned how to declare and initialize a single dimensional array. This allowed you to save groups of related data all in one convenient spot. But sometimes being limited to a single column of data just isn't enough. For example, you might want to relate a list of names to their corresponding id numbers. This is where the most basic multi-dimensional array, two dimensionl arrays, come into play.

Single Dimensional Arrays

By Daniel Taylor on July 12, 2011

So far, you know how to define variables and store a predefined number. However, in most practical situations, you don't know the exact number of objects until runtime and you often need to link the objects together so they can be iterated over. Let's say you have a text file full of names that you need to read into your program, but you can't make a variable for each name because you don't know how many variables you will need. This is where arrays come in.

Properties

By Daniel Taylor on July 11, 2011

One of the main goals of developers is to desing classes around the idea of encapsulation, the hiding of the implementation of a class while exposing only the necessary members, as well as restrict direct access to fields. There are also many times in which the value being set to the field must be validated or otherwise processed. In other langauges, this is often accomplished through getter and setter methods, but C# provides an elegant solution to both of these paradigms with accessors.