<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>3D Game Programming</title>
	<atom:link href="http://www.3dgameprogramming.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3dgameprogramming.net</link>
	<description>Brecht Kets - XNA News and Tutorials - DirectX News and Tutorials</description>
	<lastBuildDate>Tue, 17 Apr 2012 13:18:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Collections Part 1</title>
		<link>http://www.3dgameprogramming.net/2012/04/11/collections-part-1/</link>
		<comments>http://www.3dgameprogramming.net/2012/04/11/collections-part-1/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 13:24:53 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/?p=212</guid>
		<description><![CDATA[Contents 1. Introduction 2. Array 2.1 General 2.2 Iterating an array 2.3 Copying arrays 3. Collections 3.1 ArrayList 3.2 BitArray 3.3 Hashtable 3.4 Queue 3.5 SortedList 3.6 Stack 1. Introduction Just like C++, C# has different types of collections you &#8230; <a href="http://www.3dgameprogramming.net/2012/04/11/collections-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Contents</h2>
<ul id="knol-toc-list">
<li><a href="#Introduction">1. Introduction</a></li>
<li><a href="#Array">2. Array</a>
<ul>
<li><a href="#ArrayGeneral">2.1 General</a></li>
<li><a href="#Iterating_an_array">2.2 Iterating an array</a></li>
<li><a href="#Copying_arrays">2.3 Copying arrays</a></li>
</ul>
</li>
<li><a href="#Collections">3. Collections</a>
<ul>
<li><a href="#ArrayList">3.1 ArrayList</a></li>
<li><a href="#BitArray">3.2 BitArray</a></li>
<li><a href="#Hashtable">3.3 Hashtable</a></li>
<li><a href="#Queue">3.4 Queue</a></li>
<li><a href="#SortedList">3.5 SortedList</a></li>
<li><a href="#Stack">3.6 Stack</a></li>
</ul>
</li>
</ul>
<h2 id="Introduction">1. Introduction</h2>
<div>Just like C++, C# has different types of collections you can use to manage data. In this knol, we’ll discuss arrays and the containers from the System.Collections namespace.</div>
<div> </div>
<div><span style="text-decoration: underline;">Note</span> that the containers of the System.Collections namespace are not recommended. The reason is that they cause a lot of boxing and unboxing. You should use generic collections from the System.Collections.Generic namespace (like List&lt;T&gt;), which I will explain in part 2.</div>
<div> </div>
<h2 id="Array">2. Array</h2>
<h3 id="ArrayGeneral"><strong>2.1 General</strong></h3>
<div>Unlike C++, where an array is just a pointer to the first item in that array, in C# an array is an object of type System.Array. This means an array is a real class with properties and methods, which makes handling arrays a lot easier in C# than C++. You also can’t go beyond the memory allocation of the array. If you try to access an element outside of the bounds of the array, you will get an IndexOutOfRange exception.</div>
<div> </div>
<div>Just like C++, an array is a sequence of elements, and all elements must be of the same type. The elements also live in a continuous block of memory.</div>
<div> </div>
<div>Declaring an array is similar to the way you do it in C++, except the fact that you put the square brackets after the type, not the variable name.</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';">[] arr = </span><span style="color: #0000ff; font-family: 'Courier New';">new</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> [5];</span></span></p>
<div>The code above creates an array of integers, that reserves memory for 5 elements.  You always have to call new in order to create a new array. The size of the array can be determined at runtime. The code below is completely valid (assuming you enter the correct input in the console).</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';">[] arr = </span><span style="color: #0000ff; font-family: 'Courier New';">new</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';">[</span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';">.Parse(</span><span style="color: #2b91af; font-family: 'Courier New';">Console</span><span style="font-family: 'Courier New';">.ReadLine())];</span></span></p>
<div>When you create an array instance, all elements are initialized to their default value (depending on their type). You can also initialize the elements to a specific value, by specifying them between curly braces.</div>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] arr = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;"> [5] {1,2,3,4,5};</span></p>
<div>Or even shorter:</div>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] arr = {1,2,3,4,5};</span></p>
<h3 id="Iterating_an_array"><strong>2.2 Iterating an array</strong></h3>
<div>An array has a property Length, which tells you how many items the array contains. This property makes iterating an array very easy.</div>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">for</span><span style="font-family: 'Courier New'; font-size: small;"> (</span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;"> i = 0; i &lt; arr.Length; ++i)<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(i.ToString());</span></p>
<div>You can also use the foreach statement to iterate through an array, and all collections as a matter of a fact. This is because they implement the IEnumerable interface. In future knols, you will learn more of IEnumerable, but for now it’s enough if you know that implementing the interface enables you to loop through a collection using a foreach statement.</div>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">foreach</span><span style="font-family: 'Courier New'; font-size: small;">(</span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;"> i </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">in</span><span style="font-family: 'Courier New'; font-size: small;"> arr)<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(i.ToString());</span></p>
<div>Foreach always iterates though all the items of the collection, from the first to the last element. If you want to iterate backwards, or skip certain items, you must use the ‘for’ statement.</div>
<div> </div>
<h3 id="Copying_arrays"><strong>2.3 Copying arrays</strong></h3>
<h4>2.3.1 Shallow and deep copy</h4>
<div>First of all, it’s necessary that you know the difference between shallow and deep copy. If the elements that your array contains are reference types, a shallow copy will copy the references, but not the objects to which they point. So after the copy operation both the original and the copy point to the same objects. A deep copy will clone the objects themselves, so the original and the copy don’t point to the same objects.</div>
<div> </div>
<div>All copy methods you will see below perform shallow copying. If you want to create a deep copy, you’ll need to write the code yourself.</div>
<div> </div>
<h4>2.3.2 Copy</h4>
<div>The System.Array class has a static method Copy. You can use this method to create a shallow copy of an array. It takes the original array, the destination array and the length as arguments.</div>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] original = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[10] { 1, 2, 3, 4, 5 };<br /></span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] copy = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[5];</span></p>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Array</span><span style="font-family: 'Courier New'; font-size: small;">.Copy(original, copy, 5);</span></p>
<h4>2.3.3 CopyTo</h4>
<div>Another way to copy an array is to use the CopyTo method. It takes to destination array and a starting index as arguments.</div>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] original = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[5] { 1, 2, 3, 4, 5 };<br /></span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] copy = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[5];</span></p>
<p><span style="font-family: 'Courier New'; font-size: small;">original.CopyTo(copy, 0);</span></p>
<h4>2.3.4 Clone</h4>
<div>An array also has a Clone method, which creates a shallow copy of the array and returns the copy. The Clone method creates the <span style="text-decoration: underline;">object</span> for you; you do have to cast the return value to the appropriate type.</div>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] original = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[5] { 1, 2, 3, 4, 5 };<br /></span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[] copy = (</span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">int</span><span style="font-family: 'Courier New'; font-size: small;">[]) original.Clone();</span></p>
<h2 id="Collections">3. Collections</h2>
<div>Unlike C++, it is safe to use arrays in C#. However they do have certain limitations. In the System.Collections namespace, several collections that will make your life easier are provided. All collections implement the IEnumerable interface, so you can make use of the foreach statement. Most collections from the System.Collection namespace use object as type for their elements. So <span style="color: #0000ff;">object</span>[] instead of <span style="color: #0000ff;">int</span>[] for example. The System.Collections.Generics namespace offers a solution for that. This will be discussed in the 2<sup><span style="font-size: small;">nd</span></sup>collections knoll.</div>
<div> </div>
<h3 id="ArrayList"><strong>3.1 ArrayList</strong></h3>
<div>An arraylist is a collection that doesn’t have a fixed number of elements like an array does. It’s also very useful when you want to add, insert and remove a lot of elements at runtime.</div>
<div> </div>
<div>When you use an array and you want to resize it, you have to create a new one, copy the elements, update references, … Removing items from the array means you’ll have to move all trailing elements, … The arraylist does all this for you. You use an ArrayList as is shown below:</div>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Create a new arraylist<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">ArrayList</span><span style="font-family: 'Courier New'; font-size: small;"> myAL = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">ArrayList</span><span style="font-family: 'Courier New'; font-size: small;">();<br /></span><span style="font-family: 'Courier New'; font-size: small;">myAL.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;Hello&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">myAL.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;!&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Insert World between Hello and !<br /></span><span style="font-family: 'Courier New'; font-size: small;">myAL.Insert(1, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;World&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Add two items to the end of the arraylist<br /></span><span style="font-family: 'Courier New'; font-size: small;">myAL.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;test&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">myAL.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;test2&#8243;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Remove the items that have &#8220;test&#8221; as value<br /></span><span style="font-family: 'Courier New'; font-size: small;">myAL.Remove(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;test&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Remove the item at index 3<br /></span><span style="font-size: small;">myAL.RemoveAt(3);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Displays the properties and values of the ArrayList.<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;myAL&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;    Count:    {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, myAL.Count);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;    Capacity: {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, myAL.Capacity);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;    Values:&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Write all objects to console. Note the object keyword!<br /></span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">foreach</span><span style="font-family: 'Courier New'; font-size: small;"> (</span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Object</span><span style="font-family: 'Courier New'; font-size: small;"> obj </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">in</span><span style="font-family: 'Courier New'; font-size: small;"> myAL)<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;   {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, obj);</span> </p>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine();</span></p>
<h3 id="BitArray"><strong>3.2 BitArray</strong></h3>
<div>The BitArray container is a compact array of bit values that represent booleans. 1 indicates that the bit is on (true), 0 that the bit is off (false).</div>
<div> </div>
<h3 id="Hashtable"><strong>3.3 Hashtable</strong></h3>
<div>An arraylist for example, makes it easy to map an integer (index) to a certain value. But sometimes we want the key (the index) to be something different than an integer.  A hashtable has two arrays internally, one for the keys, and one for the objects. A hashtable is very similar to the C++ map.</div>
<div> </div>
<div>There are some things one should be aware of however:</div>
<ol>
<li>
<div>A hashtable cannot contain duplicate keys.</div>
</li>
<li>
<div>A hashtable can contain duplicate values.</div>
</li>
<li>
<div>When using the foreach statement on a hashtable, you get back objects of type DictionaryEntry.</div>
</li>
</ol>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Hashtable</span><span style="font-family: 'Courier New'; font-size: small;"> openWith = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Hashtable</span><span style="font-family: 'Courier New'; font-size: small;">();</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Add some elements to the hash table. There are no<br /></span><span style="font-size: small;">// duplicate keys, but some of the values are duplicates.<br /></span><span style="font-family: 'Courier New'; font-size: small;">openWith.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;txt&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;notepad.exe&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">openWith.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;bmp&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;paint.exe&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">openWith.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;dib&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;paint.exe&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">openWith.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;rtf&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;wordpad.exe&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// The Add method throws an exception if the new key is<br /></span><span style="font-size: small;">// already in the hash table.<br /></span><span style="font-size: small;">try<br /></span><span style="font-size: small;">{<br /></span>     <span style="font-family: 'Courier New'; font-size: small;">openWith.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;txt&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;winword.exe&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-size: small;">}<br /></span><span style="font-size: small;">catch<br /></span><span style="font-size: small;">{<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;An element with Key = \&#8221;txt\&#8221; already exists.&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-size: small;">}</span></p>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">foreach</span><span style="font-family: 'Courier New'; font-size: small;"> (</span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">DictionaryEntry</span><span style="font-family: 'Courier New'; font-size: small;"> entry </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">in</span><span style="font-family: 'Courier New'; font-size: small;"> openWith)<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;   {0}, {1}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, entry.Key, entry.Value);</span></p>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine();</span></p>
<h3 id="Queue"><strong>3.4 Queue</strong></h3>
<div>The queue in C# is very similar to the C++ queue. It’s a collection that implements the first-in, first-out (FIFO) principle. Items that are queued are inserted at the back, and removed from the front.</div>
<div> </div>
<div>Usage is very straightforward:</div>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Queue</span><span style="font-family: 'Courier New'; font-size: small;"> myQ = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Queue</span><span style="font-family: 'Courier New'; font-size: small;">();<br /></span><span style="font-family: 'Courier New'; font-size: small;">myQ.Enqueue(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;Hello&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">myQ.Enqueue(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;World&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">myQ.Enqueue(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;!&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Displays the properties and values of the Queue.<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;myQ&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;\tCount:    {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, myQ.Count);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;\tValues:&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Write all items to the console<br /></span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">foreach</span><span style="font-family: 'Courier New'; font-size: small;"> (</span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Object</span><span style="font-family: 'Courier New'; font-size: small;"> obj </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">in</span><span style="font-family: 'Courier New'; font-size: small;"> myQ)<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;   {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, obj);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// dequeue the first item (Hello)<br /></span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">string</span><span style="font-family: 'Courier New'; font-size: small;"> hello = (</span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">string</span><span style="font-family: 'Courier New'; font-size: small;">) myQ.Dequeue();<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine();</span></p>
<h3 id="SortedList">3.5 SortedList</h3>
<div>A sorted list is very similar to a hashtable, except that the values are sorted by key. The usage and restrictions of the sorted list are similar to the hashtable.</div>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// The items will be sorted by key<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">SortedList</span><span style="font-family: 'Courier New'; font-size: small;"> mySL = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">SortedList</span><span style="font-family: 'Courier New'; font-size: small;">();<br /></span><span style="font-family: 'Courier New'; font-size: small;">mySL.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;First&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;Hello&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">mySL.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;Third&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;!&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">mySL.Add(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;Second&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, </span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;World&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Displays the properties and values of the SortedList.<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;mySL&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;  Count:    {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, mySL.Count);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;  Capacity: {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, mySL.Capacity);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;  Values:&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">foreach</span><span style="font-family: 'Courier New'; font-size: small;"> (</span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">DictionaryEntry</span><span style="font-family: 'Courier New'; font-size: small;"> entry </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">in</span><span style="font-family: 'Courier New'; font-size: small;"> mySL)<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;   {0}, {1}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, entry.Key, entry.Value);</span></p>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine();</span></p>
<h3 id="Stack"><strong>3.6 Stack</strong></h3>
<div>The stack in C# is also very similar to the C++ stack. It’s a collection that implements the last-in, first-out (LIFO) principle. An element is added (push) to the top of the stack, and removed (pop) from the top as well.</div>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Stack</span><span style="font-family: 'Courier New'; font-size: small;"> myStack = </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">new</span><span style="font-family: 'Courier New'; font-size: small;"> </span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Stack</span><span style="font-family: 'Courier New'; font-size: small;">();<br /></span><span style="font-family: 'Courier New'; font-size: small;">myStack.Push(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;Hello&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">myStack.Push(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;World&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="font-family: 'Courier New'; font-size: small;">myStack.Push(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;!&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Displays the properties and values of the Stack.<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;myStack&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;\tCount:    {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, myStack.Count);<br /></span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;\tValues:&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">);</span> </p>
<p><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">foreach</span><span style="font-family: 'Courier New'; font-size: small;"> (</span><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Object</span><span style="font-family: 'Courier New'; font-size: small;"> obj </span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">in</span><span style="font-family: 'Courier New'; font-size: small;"> myStack)<br /></span>     <span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.Write(</span><span style="color: #a31515; font-family: 'Courier New'; font-size: small;">&#8220;   {0}&#8221;</span><span style="font-family: 'Courier New'; font-size: small;">, obj);</span> </p>
<p><span style="color: #008000; font-family: 'Courier New'; font-size: small;">// Pop the first item (!)<br /></span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">string</span><span style="font-family: 'Courier New'; font-size: small;"> exlamationmark = (</span><span style="color: #0000ff; font-family: 'Courier New'; font-size: small;">string</span><span style="font-family: 'Courier New'; font-size: small;">)myStack.Pop();</span> </p>
<p><span style="color: #2b91af; font-family: 'Courier New'; font-size: small;">Console</span><span style="font-family: 'Courier New'; font-size: small;">.WriteLine();</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2012/04/11/collections-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Value types and reference types</title>
		<link>http://www.3dgameprogramming.net/2012/04/11/value-types-and-reference-types/</link>
		<comments>http://www.3dgameprogramming.net/2012/04/11/value-types-and-reference-types/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 08:26:48 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/?p=183</guid>
		<description><![CDATA[Contents Introduction Value Types Reference Types Ref and Out parameters General Ref Out Nullable Types General Introduction When programming in C#, it is of utter importance that you understand the differences between value types and reference types, because using them &#8230; <a href="http://www.3dgameprogramming.net/2012/04/11/value-types-and-reference-types/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Contents</h2>
<ul>
<li><a href="#Introduction">Introduction</a></li>
<li><a href="#Value_Types">Value Types</a></li>
<li><a href="#Reference_Types">Reference Types</a></li>
<li><a href="#Ref_and_Out_parameters">Ref and Out parameters</a>
<ul>
<li><a href="#GeneralRefOut">General</a></li>
<li><a href="#Ref">Ref</a></li>
<li><a href="#Out">Out</a></li>
</ul>
</li>
<li><a href="#Nullable_Types">Nullable Types</a>
<ul>
<li><a href="#NullableGeneral">General</a></li>
</ul>
</li>
</ul>
<h2 id="Introduction">Introduction</h2>
<div>When programming in C#, it is of utter importance that you understand the differences between value types and reference types, because using them has consequences that will become apparent after reading this document.</div>
<h2 id="Value_Types">Value Types</h2>
<div>Types such as int, float, double, char, structs, … are value types. This means that when you declare a variable of such a type, the compiler will allocate a block of memory that is large enough to contain the corresponding value. For example, the compiler will allocate 4 bytes of memory when you declare a variable of type int. When assigning a value to this variable (example 1), the block of memory will be copied.</div>
<div><span style="text-decoration: underline;">Example 1:</span></div>
<div>Declare a variable of type integer (i) and initialize it to 1. Then declare a second variable of type integer (y), and assign it to the value of i. Executing i++ doesn’t affect y, because a copy is made.</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> i = 1; </span><span style="color: #008000; font-family: 'Courier New';">// Declare and initialize i</span></span></p>
<p><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> y = i; </span><span style="color: #008000; font-family: 'Courier New';">// Make a copy</span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">i++; </span><span style="color: #008000; font-family: 'Courier New';">// Increment i, y doesn’t change</span></span></p>
<div><img title="Value Types" src="http://www.3dgameprogramming.net/wp-content/uploads/2012/04/Value_Types.png" alt="Value Types" /></div>
<div> </div>
<div>It is often stated that value types reside on the stack and reference types reside on the heap. This is incorrect. Value types are types which reside in their own memory, and don’t have a pointer to them. The type of an object doesn&#8217;t really have anything to do with the place where it&#8217;s stored; it&#8217;s the lifetime that matters. More info about this confusion can be found in the article “<a href="http://blogs.msdn.com/b/ericlippert/archive/2010/09/30/the-truth-about-value-types.aspx">The truth about value types</a>”.</div>
<div>In C#, almost all primitives are value types, with string as an exception. All structs are also value types. This has some consequences.</div>
<div>An example: a form has a property Location that you can use to set the location of your form. This property is a struct. When I access the location of the form, I get back a copy. This means you can’t change the location like follows:</div>
<p><span style="font-size: small; font-family: 'courier new', courier;"><span style="color: #0000ff;">this</span>.Location.X = 3;</span></p>
<p>This code will result in a compiler error, although it looks like reasonable code. Let us write the code above in C++:</p>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">this</span><span style="font-family: 'Courier New';">-&gt;getLocation().setX(3);</span></span></p>
<p>Obviously this doesn&#8217;t have the intented effect: getLocation returns a local copy of the location, and setX would change this local copy, having no effect on the instance itself.</p>
<p>You have to use the following workaround:</p>
<p><span style="font-size: small;"><span style="color: #2b91af; font-family: 'Courier New';">Point</span><span style="font-family: 'Courier New';"> loc = </span><span style="color: #0000ff; font-family: 'Courier New';">this</span><span style="font-family: 'Courier New';">.Location;<br /> </span>loc.X = 3;<br /> <span style="color: #0000ff; font-family: 'Courier New';">this</span><span style="font-family: 'Courier New';">.Location = loc;</span></span></p>
<h2 id="Reference_Types">Reference Types</h2>
<div>When declaring an object that is a reference type, the compiler takes different actions than with value types. The compiler won’t allocate a block of memory that is large enough to contain your object. Instead it will allocate a small block of memory that can contain a reference (managed pointer) to your object. It is often said that references go on the stack because they themselves are value types. This is incorrect. References aren’t value types, they’re just values (they have no type in the c# type system). The reference does point to your object, which resides on the heap. So reference types have references to blocks of memory on the heap.</div>
<div>Objects of type string are also reference types, as the keyword string is just an alias for the class System.String.</div>
<div><span style="text-decoration: underline;">Example</span>:</div>
<div>Declare a variable of type Button (button1). This variable can point to a Button object. Declare a second variable of type Button (button2). When I assign the value of button1 to button2, both references point to the same object. There is only 1 Button object, but there are two references. When changing button2, button1 also changes.</div>
<p><span style="font-size: small;"><span style="color: #008000; font-family: 'Courier New';">// Declare and initialize a new Button<br /> </span><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';"> button1 = </span><span style="color: #0000ff; font-family: 'Courier New';">new</span><span style="font-family: 'Courier New';"> </span><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';">(); </span> </span></p>
<p><span style="font-size: small;"><span style="color: #008000; font-family: 'Courier New';">// Declare a variable of type Button and let it point to button1<br /> </span><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';"> button2 = button1;</span> </span></p>
<p><span style="font-size: small;"><span style="color: #008000; font-family: 'Courier New';">// button2 also changes the text of button1, because<br /> </span><span style="color: #008000; font-family: 'courier new', courier;">// only 1 object exists</span><br /> <span style="font-family: 'Courier New';">button2.Text = (</span><span style="color: #a31515; font-family: 'Courier New';">&#8220;I also change button1&#8243;</span><span style="font-family: 'Courier New';">);</span> </span></p>
<div><img title="Reference Types" src="http://www.3dgameprogramming.net/wp-content/uploads/2012/04/Reference_Types.png" alt="Reference Types" /></div>
<div> </div>
<div>One consequence of reference types is that you can changes these from within a method. An example: when I pass button1 as argument to a function, this function can change the object. With value types, you would just pass a copy.</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> ReferenceDemo(</span><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';"> btn)<br /> </span><span style="font-family: 'Courier New';">{<br /> </span><span style="font-family: 'Courier New';">   </span>     <span style="color: #008000; font-family: 'Courier New';">// I change the original Button here<br /> </span><span style="color: #008000; font-family: 'Courier New';">   </span>     <span style="font-family: 'Courier New';">btn.Text = </span><span style="color: #a31515; font-family: 'Courier New';">&#8220;changed&#8221;</span><span style="font-family: 'Courier New';">;<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
<div>Note that in C#, there is no way to pass the button object as a const argument.</div>
<p>&nbsp;</p>
<h2 id="Ref_and_Out_parameters">Ref and Out parameters</h2>
<h3 id="GeneralRefOut"><strong>General</strong></h3>
<div>When passing an argument to a method or function, a copy is passed by default. This is true for value types <span style="text-decoration: underline;">and</span> reference types. It is however so that with reference types, a copy of the reference is passed, and the object to whom it refers stays the same. This has as a consequence that you can’t change the value of the parameter passed.</div>
<div><span style="text-decoration: underline;">Example</span>:</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> ReferenceDemo(</span><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';"> btn)<br /> </span><span style="font-family: 'Courier New';">{<br /> </span><span style="font-family: 'Courier New';">   </span>     <span style="color: #008000; font-family: 'Courier New';">// I change the original Button here<br /> </span><span style="color: #008000; font-family: 'Courier New';">   </span>     <span style="font-family: 'Courier New';">btn.Text = </span><span style="color: #a31515; font-family: 'Courier New';">&#8220;changed&#8221;</span><span style="font-family: 'Courier New';">;</span></span><br /> <span style="font-size: small;"> <span style="font-family: 'Courier New';"><span style="font-family: arial, helvetica, sans-serif;"><br /> </span>     </span><span style="color: #008000; font-family: 'Courier New';">// The original reference isn’t changed<br /> </span><span style="color: #008000; font-family: 'Courier New';">   </span>     <span style="font-family: 'Courier New';">btn = </span><span style="color: #0000ff; font-family: 'Courier New';">null</span><span style="font-family: 'Courier New';">;<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
<div>In the method above, it is possible to change the text of the button, but making the reference point to null has no impact on the original object, only on the copy of the reference which has been passed to the method ReferenceDemo.</div>
<div>On the other hand, when I pass a variable of type int as parameter to a method, I can’t change the value of the original int. In C++, you would pass an int-reference (not to be mistaken with a C# reference) to solve this.</div>
<div>In C#, there are 2 ways to get the results we want, via the keywords ref and out.</div>
<h3 id="Ref"><strong>Ref</strong></h3>
<div>When you place the ref keyword before the type of an argument, the parameter becomes an alias to the argument, and not a copy. So by using the ref keyword, you <span style="text-decoration: underline;">can </span>change the original object.</div>
<div><span style="text-decoration: underline;">Example 1: int</span></div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> RefDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">ref</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> i)<br /> </span><span style="font-family: 'Courier New';">{<br /> </span><span style="font-family: 'Courier New';">   </span>     <span style="color: #008000; font-family: 'Courier New';">// I change the original object here<br /> </span><span style="color: #008000; font-family: 'Courier New';">   </span>     <span style="font-family: 'Courier New';">i = 3;<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
<div><span style="text-decoration: underline;">Example 2: Button</span></div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> ReferenceDemo(ref </span><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';"> btn)<br /> </span><span style="font-family: 'Courier New';">{<br /> </span><span style="font-family: 'Courier New';">   </span>     <span style="color: #008000; font-family: 'Courier New';">// I change the original object here<br /> </span><span style="color: #008000; font-family: 'Courier New';">   </span>     <span style="font-family: 'Courier New';">btn.Text = </span><span style="color: #a31515; font-family: 'Courier New';">&#8220;changed&#8221;</span><span style="font-family: 'Courier New';">;</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">      </span><span style="color: #008000; font-family: 'Courier New';">// The original reference <span style="text-decoration: underline;">is</span> changed<br /> </span><span style="color: #008000; font-family: 'Courier New';">   </span>     <span style="font-family: 'Courier New';">btn = </span><span style="color: #0000ff; font-family: 'Courier New';">null</span><span style="font-family: 'Courier New';">;<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
<div>To call a method which has a ref parameter as argument, you also need to add the ref keyword during the method call:</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> i = 10;</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">RefDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">ref</span><span style="font-family: 'Courier New';"> i);</span></span></p>
<p><span style="font-size: small;"><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';"> btn = </span><span style="color: #0000ff; font-family: 'Courier New';">new</span><span style="font-family: 'Courier New';"> </span><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';">();</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">ReferenceDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">ref</span><span style="font-family: 'Courier New';"> btn);</span></span></p>
<div>One thing you have to be aware of when using the ref keyword is that the variable has to be initialized in order to pass it as an argument to a method. The code below will result in a compile error.</div>
<p><span style="font-size: small;"><span style="color: #2b91af; font-family: 'Courier New';">Button</span><span style="font-family: 'Courier New';"> btn;</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">ReferenceDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">ref</span><span style="font-family: 'Courier New';"> btn);</span></span></p>
<div>In some cases, this could be a problem. Sometimes you want the method itself to initialize the variable. For example, in this case, I could want that the method ReferenceDemo has a bool as return value, that informs me if everything went right (the C++ way <img src='http://www.3dgameprogramming.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ), and as argument an object of type Button that is initialized in the method ReferenceDemo. This behavior can be obtained by making usage of the out keyword.</div>
<h3 id="Out"><strong>Out</strong></h3>
<div>The out keyword is very similar to the ref keyword. Prefixing an argument with the out keyword passes an alias to the argument, and not a copy. The only difference is that when making use of the out keyword, the method itself <span style="text-decoration: underline;">must assign a value</span> to the object. The code below will result in a compile error.</div>
<div><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> ReferenceDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">out</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> i)<br /> </span></span><span style="font-family: 'Courier New';">{</span><span style="font-size: small;">          </span></div>
<p><span style="font-family: 'Courier New'; font-size: small;">}</span></p>
<div>The code below will work:</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> i;</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">ReferenceDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">out</span><span style="font-family: 'Courier New';"> i);</span></span></p>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> ReferenceDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">out</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> i)<br /> </span><span style="font-family: 'Courier New';">{<br /> </span><span style="font-family: 'Courier New';">   </span>     <span style="font-family: 'Courier New';">i = 42;<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
<h2 id="Nullable_Types">Nullable Types</h2>
<h3 id="NullableGeneral"><strong>General</strong></h3>
<div>The keyword null is very handy when using reference types, because then you can see if the object is initialized. With value types, it is not possible to use the null keyword. The code below will result in a compile error.</div>
<div><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> i = </span><span style="color: #0000ff; font-family: 'Courier New';">null</span><span style="font-family: 'Courier New';">;</span></div>
<div>This is because null itself is a reference type. But there is a way to assign null to a value type, by using the ‘?’ operand. An example will clarify things.</div>
<div><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';">? i = </span><span style="color: #0000ff; font-family: 'Courier New';">null</span><span style="font-family: 'Courier New';">;</span></div>
<p>&nbsp;</p>
<div>The code above works, but what happens? The C# compiler will make an object of type Nullable. Nullable is a generic structure that internally looks like this:</div>
<div><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">struct</span><span style="font-family: 'Courier New';"> </span><span style="color: #2b91af; font-family: 'Courier New';">Nullable</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">where</span><span style="font-family: 'Courier New';"> T : </span><span style="color: #0000ff; font-family: 'Courier New';">struct<br /> </span></span><span style="font-size: small;">{</span></div>
<p><span style="font-size: small;"> <span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> Nullable(T value);</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">static</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">explicit</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">operator</span><span style="font-family: 'Courier New';"> T(T? value);</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">static</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">implicit</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">operator</span><span style="font-family: 'Courier New';"> T?(T value);</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">bool</span><span style="font-family: 'Courier New';"> HasValue { </span><span style="color: #0000ff; font-family: 'Courier New';">get</span><span style="font-family: 'Courier New';">; }</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> T Value { </span><span style="color: #0000ff; font-family: 'Courier New';">get</span><span style="font-family: 'Courier New';">; }</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">override</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">bool</span><span style="font-family: 'Courier New';"> Equals(</span><span style="color: #0000ff; font-family: 'Courier New';">object</span><span style="font-family: 'Courier New';"> other);</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">override</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> GetHashCode();</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> T GetValueOrDefault();</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> T GetValueOrDefault(T defaultValue);</span></span></p>
<p><span style="font-size: small;"><span style="font-family: 'Courier New';">        </span><span style="color: #0000ff; font-family: 'Courier New';">public</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">override</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">string</span><span style="font-family: 'Courier New';"> ToString();<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
<div>The rule<span style="font-size: small;"> <span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';">? i</span> </span>creates an object of type Nullable with as generic parameter an integer. Take into account that this object is still a value type (Nullable is a struct). Note that the Nullable class has a property HasValue; because it is possible to assign null to the variable, there has to be a way to see if the object has a value.</div>
<div>Also note that when you want to pass a nullable type as argument to a method, this also has to be a nullable type.</div>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"><strong>?</strong> i = </span><span style="color: #0000ff; font-family: 'Courier New';">null</span><span style="font-family: 'Courier New';">;</span></span></p>
<p><span style="font-family: 'Courier New'; font-size: small;">NullableDemo(i);</span></p>
<p><span style="font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> NullableDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"><strong>?</strong> i)<br /> </span><span style="font-family: 'Courier New';">{<br /> </span><span style="font-family: 'Courier New';">   </span>     <span style="color: #0000ff; font-family: 'Courier New';">if</span><span style="font-family: 'Courier New';">(i.HasValue)<br /> </span><span style="font-family: 'Courier New';">      </span>     <span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> valueOfi = i.Value;<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
<div>The code above can also be written as follows:</div>
<p><span style="font-family: 'Courier New'; font-size: small;"><span style="color: #0000ff; font-family: 'Courier New';">private</span><span style="font-family: 'Courier New';"> </span><span style="color: #0000ff; font-family: 'Courier New';">void</span><span style="font-family: 'Courier New';"> NullableDemo(</span><span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"><strong>?</strong> i)<br /> </span><span style="font-family: 'Courier New';">{<br /> </span><span style="font-family: 'Courier New';">   </span>     <span style="color: #0000ff; font-family: 'Courier New';">if</span><span style="font-family: 'Courier New';">(i != null)<br /> </span><span style="font-family: 'Courier New';">      </span>     <span style="color: #0000ff; font-family: 'Courier New';">int</span><span style="font-family: 'Courier New';"> valueOfi = (<span style="color: #0000ff; font-family: 'Courier New';">int</span>) i;<br /> </span><span style="font-family: 'Courier New';">}</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2012/04/11/value-types-and-reference-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An introduction to C# and the .NET framework</title>
		<link>http://www.3dgameprogramming.net/2012/04/10/an-introduction-to-c-and-the-net-framework/</link>
		<comments>http://www.3dgameprogramming.net/2012/04/10/an-introduction-to-c-and-the-net-framework/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 12:13:26 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/?p=147</guid>
		<description><![CDATA[1. Introduction C# is an object oriented programming language built on top of the .NET framework. C# Is a higher level language that enables you to write code fast. Compared to C++, there are some differences one should be aware &#8230; <a href="http://www.3dgameprogramming.net/2012/04/10/an-introduction-to-c-and-the-net-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>1. Introduction</h2>
<div>C# is an object oriented programming language built on top of the .NET framework. C# Is a higher level language that enables you to write code fast. Compared to C++, there are some differences one should be aware of. These differences will be handled in this article. This article will not offer you in depth knowledge about C# and the .NET framework, but rather glance at the differences. You will gain in depth knowledge in future articles. At the moment of writing, we&#8217;re at C# version 4.</div>
<p></p>
<h2>2. .NET framework</h2>
<h3><strong><span style="font-size: medium;">2.1 General</span></strong></h3>
<div>The .NET framework is built by Microsoft. It offers seamless collaboration between libraries written in different programming languages. .NET is a managed framework, meaning certain things are handled for you, such as garbage collection. .NET programs aren&#8217;t, unlike C++, compiled to machine code, but rather to an intermediate language, called CIL (Common Intermediate Language). This CIL code is then translated to machine code at run time by the CLR (Common Language Runtime), by making usage of JIT (Just In Time) compilation.</div>
<div>There are several programming languages you can use to develop on the .NET framework, such as C#, VB.NET, C++/CLI, Boo, &#8230; All these languages are compiled to the same CIL. Because all programs are compiled to an intermediate language, it&#8217;s also fairly easy to decompile it again (to the same, or another programming language). If you want to decompile .NET code, take a look at <a href="http://www.red-gate.com/products/reflector/">Reflector.NET</a>.</div>
<p></p>
<h3><strong><span style="font-size: medium;">2.2 History</span></strong></h3>
<div>2002: .NET framework 1.0 + Visual Studio 2002</div>
<div>2003: .NET framework 1.1 + Visual Studio 2003</div>
<div>2005: .NET framework 2.0 + Visual Studio 2005</div>
<div>2006: .NET framework 3.0</div>
<div>2007: .NET framework 3.5 + Visual Studio 2008</div>
<div>2010: .NET framework 4.0 + Visual Studio 2010</div>
<p></p>
<h3><strong><span style="font-size: medium;">2.3 Advantages and Disadvantages</span></strong></h3>
<div>
<p>Development using the .NET framework has its advantages and disadvantages when comparing to development in C++. Let us start with the advantages. First of all, you can develop a lot <span style="text-decoration: underline;">faster</span> when compared to C++. One might say that you produce code at about 5 times the speed than you would in C++. Second of all, it&#8217;s a lot <span style="text-decoration: underline;">easier</span> an more <span style="text-decoration: underline;">accessible</span> than C++. And you have a <span style="text-decoration: underline;">garbage collection</span> system which offers automatic deallocation, eliminating almost all memory leaks. It&#8217;s also cross platform, meaning your code will work on several versions of Windows, and if you use the compact framework, your code will work on mobile devices, Xbox 360 and Windows Phone. With the help <a href="http://www.mono-project.com/Main_Page">Mono</a>, your code will even run on Linux (Note: not all .NET features are supported on Mono). The Unity3D gamdev IDE is built on top of Mono.</p>
<div>Development using the .NET code also has some disadvantages. First of all, because your code is compiled to an intermediate language, it&#8217;s a lot easier to decompile code than it would be with C++ code. Luckily several obfuscating techniques exist that make this process more difficult. The garbage collector (&#8220;GC&#8221;) can also be a disadvantage. One has to have a good understanding about what it does to make sure it doesn&#8217;t become a bottleneck. The GC on the Windows is fairly advanced,  but the one on the compact framework isn&#8217;t as effective. When building games in XNA for Xbox 360 and Phone 7 Series, the GC will be something you will have to pay attention to. Then the final thing is that .NET code can run slower than C++. But let us be honest, isn&#8217;t this the same discussion that we have when moving from Assembler to C? Or from C to C++? Also, bear into mind that it&#8217;s fairly easy to write slow C++ code if you don&#8217;t know what you&#8217;re doing; doing so in .NET is a bit harder since the framework manages a lot for you.</div>
<p></p>
<h2>3. The C# programming language</h2>
<h3><strong><span style="font-size: medium;">3.1 Introduction</span></strong></h3>
<div>C# (pronounced C Sharp) is an object oriented programming language developed by Microsoft. It is accepted as a standard by the ECMA (ECMA-334) and ISO (ISO/IEC 23270). C# has an object oriented, procedural syntax and is based upon the C++ syntax. It also has some Java elements, and even some functional and dynamic programming language influences. At the moment of writing, C# is at version 4.0. The Microsoft compiler for C# 4.0 was released in 2010, but the language specification dates from 2006.</div>
<div>Now let us start with mentioning some differences between C# and C++.</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.2 Everything is an Object</span></strong></h3>
<div>In C#, and the .NET framework, everything inherits from System.Object. This leads to the fact that in C#, you could write the following code:</div>
<p></p>
<div>
<div>            (7).ToString();</div>
<div>            <span style="color: #990000;">&#8220;THIS IS A STRING&#8221;</span>.CompareTo(<span style="color: #990000;">&#8220;SECOND STRING&#8221;</span>);</div>
<p>
</div>
<div>This means you can also cast <span style="text-decoration: underline;">everything</span> to System.Object, since they&#8217;re all derived from that base class.</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.3 Headers</span></strong></h3>
<div>C# doesn&#8217;t use header files. Because .NET is compiled to an intermediate language, there is no need for header files, since the DLLs it compiles to (called &#8220;assemblies&#8221;) contain all information about the classes and methods in it.</div>
<p></p>
<div>Take a look at the class below:</div>
<p></p>
<div>
<div><span style="font-family: arial, sans-serif;">    <span style="color: #0000ff;"><strong>public class</strong></span> <span style="color: #45818e;">Hero</span></span></div>
<div><span style="font-family: arial, sans-serif;">   {</span></div>
<div><span style="color: #38761d; font-family: arial, sans-serif;">        // FIELD (called data member in C++)</span></div>
<div><span style="font-family: arial, sans-serif;">        <span style="color: #0000ff;"><strong>private </strong>string </span>_nemesis;</span></div>
<div><span style="font-family: arial, sans-serif;">       <span style="color: #00ff00;"> </span><span style="color: #38761d;">// CONSTRUCTOR</span></span></div>
<div><span style="font-family: arial, sans-serif;">        <span style="color: #0000ff;"><strong>public </strong></span>Hero()</span></div>
<div><span style="font-family: arial, sans-serif;">        {</span></div>
<div>
<p><span style="font-family: arial, sans-serif;">        </span><span style="font-family: arial, sans-serif;">}</span></p>
<div><span style="font-family: arial, sans-serif;">       <span style="color: #00ff00;"> </span><span style="color: #38761d;">// NO DESTRUCTOR IS NEEDED!!!</span></span></div>
<div></div>
<div><span style="font-family: arial, sans-serif;">       <span style="color: #00ff00;"> </span><span style="color: #38761d;">// METHOD (called member function in C++)</span></span></div>
<div><span style="font-family: arial, sans-serif;">        <span style="color: #0000ff;"><strong>public </strong></span>void SaveTheWorld()</span></div>
<div><span style="font-family: arial, sans-serif;">        { </span></div>
<div><span style="font-family: arial, sans-serif;">        }</span></div>
<div><span style="font-family: arial, sans-serif;">        <span style="color: #0000ff;"><strong>private </strong></span>void AskForHelp()</span></div>
<div><span style="font-family: arial, sans-serif;">        { </span></div>
<div><span style="font-family: arial, sans-serif;">        }</span></div>
<div><span style="font-family: arial, sans-serif;">    }</span></div>
</div>
<div>The class itself has the &#8216;public&#8217; access specifier. Each method has its own access specifier as well. So do the fields.</div>
<div>Note that classes in C# don&#8217;t have destructors, since they are collected automatically by the GC (you do have finalizers, but these are only used when you inter-operate with native APIs like DirectX)</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.4 Pointers</span></strong></h3>
<div>C# has pointers (in unsafe mode), but you&#8217;ll almost never use them. C# has two different kinds of types: <strong>value types </strong>(structs and enums), that hold the data in its own memory allocation and <strong>reference types </strong>(classes and arrays), that store a reference to the data. Unlike C++, it is the definition of type itself that determines if the data is passed by copy or by reference.  This reference is not to be confused with C++ references. References in C# can be compared with a sort of managed pointer, without the overloaded pointer operations. This also means you shall almost never use the -&gt; operand. You can always access type members by using the &#8220;.&#8221; operand. For example, if I would want to call the method SaveTheWorld on a Hero object, I would just write the following code:</div>
<div>
</p>
<div><span style="color: #38761d; font-family: arial, sans-serif;">// Create a new instance of the Hero class, </span></div>
<div><span style="color: #38761d; font-family: arial, sans-serif;">// and store a reference to it in the hero local variable</span></div>
<div><span style="font-family: arial, sans-serif;"><span style="color: #0000ff;"><strong>Hero</strong> </span>hero = <strong>new</strong> <strong><span style="color: #0000ff;">Hero</span></strong>(); </span></div>
<div>
<div><span style="color: #38761d; font-family: arial, sans-serif;">// Call the method SaveTheWorld.</span></div>
</div>
<div><span style="font-family: arial, sans-serif;">hero.SaveTheWorld();<span style="color: #38761d;"> </span></span></div>
<div></div>
<div>
<div>In C++, this would look like:</div>
<div><span style="font-family: arial, sans-serif;"><strong><span style="color: #0000ff;">Hero</span><span style="color: #45818e;">*</span></strong><span style="color: #45818e;"> </span>hero = <strong>new</strong> <strong><span style="color: #0000ff;">Hero</span></strong>(); </span></div>
<div><span style="font-family: arial, sans-serif;">hero-&gt;SaveTheWorld();<span style="color: #38761d;"> </span></span></div>
<p>
</div>
</div>
<h3><strong><span style="font-size: medium;">3.5 Properties</span></strong></h3>
<div>C# has a special syntax for writing getters and setters, called <strong>properties</strong>. When you would want to expose a member called Nemesis, in C++, you would write the following code:</div>
<div>
<div><span style="font-family: arial, sans-serif;"><span style="color: #0000ff;"><strong>class </strong></span>Hero</span></div>
<div><span style="font-family: arial, sans-serif;">{</span></div>
<div>
<div><span style="font-family: arial, sans-serif;"><strong>public</strong>:</span></div>
<div><span style="font-family: arial, sans-serif;">  <span style="color: #0000ff;"><strong>const char</strong></span>* getNemesis() {return m_Nemesis;}</span></div>
<div><span style="font-family: arial, sans-serif;">  <strong><span style="color: #0000ff;">void</span></strong> setNemesis(const char* nemesis) {m_Nemesis = nemesis;}</span></div>
<div><span style="font-family: arial, sans-serif;"><strong>private</strong>:</span></div>
<div><span style="font-family: arial, sans-serif;"> <span style="color: #0000ff;"><strong>const char</strong></span>* m_Nemesis;</span></div>
<div><span style="font-family: arial, sans-serif;">};</span></div>
</div>
<div>If you want to set the name of the hero, you need to call hero-&gt;setName(&#8220;Name&#8221;).</div>
<div>In C#, you would write the code as follows:</div>
<div>
<div>
<div><span style="font-family: arial, sans-serif;"><strong>public </strong><strong>class </strong>Hero</span></div>
<div><span style="font-family: arial, sans-serif;">{</span></div>
<div><span style="font-family: arial, sans-serif;">   <span style="color: #0000ff;">private string</span> _nemesis;</span></div>
</div>
</div>
<div>
</p>
<div><span style="font-family: arial, sans-serif;">   <span style="color: #0000ff;">public string</span> Nemesis</span></div>
<div><span style="font-family: arial, sans-serif;">   {</span></div>
<div><span style="font-family: arial, sans-serif;">    <span style="color: #0000ff;">get </span>{ <span style="color: #0000ff;">return </span>_nemesis; }</span></div>
<div>
<p><span style="font-family: arial, sans-serif;">    <span style="color: #0000ff;">set </span>{ _nemesis  = <span style="color: #0000ff;">value</span>; }<br />
</span><span style="font-family: arial, sans-serif;">   }</span></p>
</div>
<div><span style="font-family: arial, sans-serif;">}</span></div>
<p></p>
<div>The C# compiler will then generate getters and setters methods for you. If you would like to set the name of the hero, you would have to write the following code:</div>
<div></div>
<div>        hero.Nemesis = <span style="color: #990000;">&#8220;nemesis&#8221;</span>;</div>
<p></p>
<div>If you would like to get the name of the nemesis, you would have to write the following code:</div>
<p></p>
<div><span style="color: #0000ff;">        string </span>nemesis = hero.Nemesis;</div>
<p></p>
<div>If the property call is on the left of the assignment operator, then the setter is called; if it is on the right side, the getter is called.</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.6 Interfaces</span></strong></h3>
<div>An interface contains the signatures of methods, delegates, events, but has no implementation. You can compare an interface with an abstract class that only contains pure virtual methods.</div>
<div>
<div>    <span style="color: #0000ff;">public interface </span><span style="color: #45818e;">IHero</span></div>
<div>    {</div>
<div>        void SaveTheWorld();</div>
<div>    }</div>
</div>
<p></p>
<div>
<div>    <span style="color: #0000ff;">public class </span><span style="color: #45818e;">Hero </span>: <span style="color: #45818e;">IHero</span></div>
<div>    {</div>
<div>        <span style="color: #0000ff;">public void</span> SaveTheWorld()</div>
<div>        {</div>
<div>            <span style="color: #38761d;">// IMPLEMENTATION</span></div>
<div>        }</div>
<div>    }</div>
</div>
<div>An interface could be seen as a blueprint of what methods a class should contain. An interface can inherit from one or more base interfaces.</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.7 Inheritance</span></strong></h3>
<div>In C#, inheritance is different than in C++. First of all, the distinction between structs and classes has to be made. <strong>Structs</strong> (value types) <span style="text-decoration: underline;">do not</span> support inheritance, <strong>classes</strong> (reference types) do. C# doesn&#8217;t have multiple inheritance where one class can be derived from several other classes. You can only derive from one base class. You can implement multiple interfaces though.</div>
<div>So our class Hero could inherit from a base class person, and still implement the IHero interface.</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.8 Arrays</span></strong></h3>
<div>An array in C# is an object of type <strong>Array</strong> (a reference type). An Array is a class (unlike C++, where an array is just a pointer to the first element of the array). An array in C# has methods and properties, such as the property Length. Another difference is that the square brackets ([]) follow the type and not the variable.</div>
<div>In C#, a variety of higher level collection classes exists, such as <strong>List</strong>, <strong>Dictionary</strong> (these are similar to C++ std::vector, std:map, &#8230;)</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.9 Strings</span></strong></h3>
<div>A C# <strong>string</strong> object is an instance of the System.String class. In C++, strings are an array of characters, and always a hassle to work with. In C#, a string is an immutable object, meaning you cannot change the string object itself.  You can however combine strings into new strings (for example concatenating two strings using the + operator).</div>
<p></p>
<h3><strong><span style="font-size: medium;">3.10 Casting</span></strong></h3>
<div>
<p>C# has support for c-style casts, just like C++, but it doesn&#8217;t have static_cast support. All casts in C# are like C++ dynamic_cast, but they will throw an exception if the object is not of the correct type.</p>
<div>object obj = &#8230;</div>
<div><span style="color: #45818e;">Hero </span>hero = (<span style="color: #45818e;">Hero</span>)obj;</div>
<p></p>
<div>You can also use the &#8216;as&#8217; keyword, which returns null it the cast fails. This is similar to the dynamic_cast in C++.</div>
<div><span style="color: #45818e;">Hero </span>hero = obj <span style="color: #0000ff;">as </span><span style="color: #45818e;">Hero</span>;</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2012/04/10/an-introduction-to-c-and-the-net-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HLSL Shaders</title>
		<link>http://www.3dgameprogramming.net/2009/01/19/hlsl-shaders/</link>
		<comments>http://www.3dgameprogramming.net/2009/01/19/hlsl-shaders/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 10:17:29 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[DirectX]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[HLSL]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/?p=125</guid>
		<description><![CDATA[Koen Samyn, lecturer interactive programming at the University College of West Flanders (curriculum Digital Arts and Entertainment) wrote an excellent KNOL (a unit of knowledge) on HLSL Shaders. You can find the article here: http://knol.google.com/k/samyn-koen/-/2lijysgth48w1/2# Extract: What is a shader &#8230; <a href="http://www.3dgameprogramming.net/2009/01/19/hlsl-shaders/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Koen Samyn, lecturer interactive programming at the University College of West Flanders (curriculum <a href="http://www.digitalartsandentertainment.com">Digital Arts and Entertainment</a>) wrote an excellent KNOL (a unit of knowledge) on HLSL Shaders. You can find the article here:<br />
<a href="http://knol.google.com/k/samyn-koen/-/2lijysgth48w1/2#">http://knol.google.com/k/samyn-koen/-/2lijysgth48w1/2#</a></p>
<p>Extract:</p>
<blockquote><p>What is a shader ?<br />
A shader ( or effect) is a program that is executed on the GPU (Graphical Processing Unit). The GPU is located on the graphics card off course and the GPU contains many cores that can execute a shader program concurrently. This allows the GPU to have high throughput (number of triangles that can be processed per second).</p>
<p>If for example a GPU has 4 available cores (run of the mill GPU have much more then that) each code transform the vertices of 4 triangles simultaneously. There are several shader API&#8217;s and languages that are targeted to curent GPU&#8217;s : &#8230;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2009/01/19/hlsl-shaders/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ziggyware Fall 2008 XNA Article Contest &#8211; Win an Xbox 360 Elite and More</title>
		<link>http://www.3dgameprogramming.net/2008/10/13/ziggyware-fall-2008-xna-article-contest-win-an-xbox-360-elite-and-more/</link>
		<comments>http://www.3dgameprogramming.net/2008/10/13/ziggyware-fall-2008-xna-article-contest-win-an-xbox-360-elite-and-more/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 08:42:39 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/?p=123</guid>
		<description><![CDATA[Ziggyware has announced a new Article Contest, where you have to write an XNA related tutorial for XNA developers. You can win an Xbox 360 Elite and several creators club subscriptions. More info: ziggyware]]></description>
			<content:encoded><![CDATA[<p>Ziggyware has announced a new Article Contest, where you have to write an XNA related tutorial for XNA developers.</p>
<p>You can win an Xbox 360 Elite and several creators club subscriptions.</p>
<p>More info: <a href="http://www.ziggyware.com/news.php?readmore=905">ziggyware</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2008/10/13/ziggyware-fall-2008-xna-article-contest-win-an-xbox-360-elite-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA 3.0 Beta Released</title>
		<link>http://www.3dgameprogramming.net/2008/09/18/xna-30-beta-released/</link>
		<comments>http://www.3dgameprogramming.net/2008/09/18/xna-30-beta-released/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 08:46:09 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/?p=121</guid>
		<description><![CDATA[Microsoft has released a Beta for XNA 3.0. This new update features many improvements and new features for Zune, XBox 360 and PC. Zune * Compatibility with the upcoming Zune 3.0 Firmware release. Please note that the XNA Game Studio &#8230; <a href="http://www.3dgameprogramming.net/2008/09/18/xna-30-beta-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Microsoft has released a Beta for XNA 3.0. This new update features many improvements and new features for Zune, XBox 360 and PC.</p>
<p><strong>Zune</strong></p>
<p>    * Compatibility with the upcoming Zune 3.0 Firmware release. Please note that the XNA Game Studio 3.0 CTP will no longer work once you have upgraded your Zune device to the 3.0 firmware.<br />
    * Improved deployment stability.<br />
    * Support for Zune deployment on Windows Vista x64 Systems!<br />
    * You can now use the Remote Performance Monitor for Zune games.</p>
<p><strong>Xbox 360</strong></p>
<p>    * Xbox 360 project templates (You will not be able to develop on the Xbox 360 until our final release. We felt this was important to include so that you could get projects converted over and look at the system, even if you are not able to run the games, yet).<br />
    * Support for the Big Button Pad.</p>
<p><strong>Framework &#038; Visual Studio Features</strong></p>
<p>    * Enumerate and play back media on your Windows computer or Xbox 360.<br />
    * Simple sound effect support on Windows computers and Xbox 360.<br />
    * Support for Rich Presence (lets friends know what&#8217;s going on in your game).<br />
    * Support for Invites (ask your friends to join you in a multiplayer game) and Join Session In Progress (after you see what your friends are doing, you can join their current session with just a couple of button presses, even if that&#8217;s a different game to the one you are currently playing)<br />
    * Compress your content and save space with the new content compression features!<br />
    * ClickOnce packaging support for distributing your XNA Framework games on Windows.<br />
    * Upgrade your project from XNA Game Studio 2.0 using the Project Upgrade Wizard!<br />
    * Take screen captures of your game running on Zune through the XNA Game Studio Device Center.<br />
    * Support for .NET language features like Linq<br />
    * Create multiple content projects and leverage cross project synchronization in Visual Studio.<br />
    * FBX importer improvements: read materials containing multiple textures, and export custom shader materials directly out of Max or Maya.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2008/09/18/xna-30-beta-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Earn Money from your Xbox LIVE Community Games</title>
		<link>http://www.3dgameprogramming.net/2008/07/23/earn-money-from-your-xbox-live-community-games/</link>
		<comments>http://www.3dgameprogramming.net/2008/07/23/earn-money-from-your-xbox-live-community-games/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 17:12:35 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/?p=119</guid>
		<description><![CDATA[Today Microsoft announced the pricing plan for your XNA Community Games on Xbox LIVE. This payment plan is fairly flexible allowing you to charget between 2.50 and 10.00 dollars for your game on Xbox LIVE. Microsoft will let you keep &#8230; <a href="http://www.3dgameprogramming.net/2008/07/23/earn-money-from-your-xbox-live-community-games/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today Microsoft announced the pricing plan for your XNA Community Games on Xbox LIVE. This payment plan is fairly flexible allowing you to charget between 2.50 and 10.00 dollars for your game on Xbox LIVE. Microsoft will let you keep 70 percent of the profit and may even advertise the game for you if it is very successful.</p>
<p><a href="http://blogs.msdn.com/xna/">Read More</a> on the XNA Team Blog<br />
<a href="http://creators.xna.com/en-us/XboxLIVECommunityGames"><br />
Xbox Live Community Games</a></p>
<p>Source: <a href="http://ziggyware.com/news.php">ziggyware</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2008/07/23/earn-money-from-your-xbox-live-community-games/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XNA games coming to the Zune, Xbox Live Arcade</title>
		<link>http://www.3dgameprogramming.net/2008/02/21/xna-games-coming-to-the-zune-xbox-live-arcade/</link>
		<comments>http://www.3dgameprogramming.net/2008/02/21/xna-games-coming-to-the-zune-xbox-live-arcade/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 20:57:30 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/2008/02/21/xna-games-coming-to-the-zune-xbox-live-arcade/</guid>
		<description><![CDATA[This morning at the Game Developers Conference in San Francisco, Microsoft announced the next step in its Xbox Live and XNA initiative: the Zune will become the third pillar supporting XNA software, with over 1,000 games ready for the device &#8230; <a href="http://www.3dgameprogramming.net/2008/02/21/xna-games-coming-to-the-zune-xbox-live-arcade/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>This morning at the Game Developers Conference in San Francisco, Microsoft announced the next step in its Xbox Live and XNA initiative: the Zune will become the third pillar supporting XNA software, with over 1,000 games ready for the device by year end. XNA software developed for the Xbox Live Arcade is now going to be opened to the public.</p>
<p>Microsoft showed off an XNA game running on a Zune during a keynote speech presented by vice president John Schappert. A top-scrolling space shooter was shown running on a PC, an Xbox 360, and, lastly, a Zune. In addition, Zune games will be multiplayer: users will be able to play against each other online. Games for the platform will be arriving this year alongside the launch of Xbox Live Community Games.</p>
<p>The new XNA-oriented service, Xbox Live Community Games, allows select user-created software to be distributed through Xbox Live, effectively opening user-created games to the masses. Titles will be selected through a democratized game distribution system pulling on the Creator&#8217;s Club user base. Members will be able to screen and vote on games, with those reaching a certain level of approval cleared and released to the public. A handful of these games are now available as trials on the Xbox Live Marketplace.</p>
<p>Creator&#8217;s Club members are paying subscribers who have access to the <a href="http://arstechnica.com/articles/xna.ars">XNA development platform</a>. Much like the gamercard, a &#8220;creator card&#8221; will show what games specific creators have built. XNA is a suite of development software which Microsoft introduced in 2006. The suite allows developers to create projects that can easily be translated between the support platforms. Previously only the PC and the Xbox 360 were supported, but the Zune represents Microsoft&#8217;s first significant step into the mobile gaming market. </p></blockquote>
<p>excerpt from <a href="http://arstechnica.com/news.ars/post/20080220-xna-games-coming-to-the-zune-xbox-live-arcade.html">http://arstechnica.com/news.ars/post/20080220-xna-games-coming-to-the-zune-xbox-live-arcade.html</a></p>
<p>A preview release of XNA Game Studio 3.0 will be available in the Spring 2008 timeframe, with a final release scheduled for the holiday 2008 season.</p>
<p><img src="http://creators.xna.com/themes/default/images/Zune_Hero_ship.png" alt="Zune" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2008/02/21/xna-games-coming-to-the-zune-xbox-live-arcade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xbox LIVE Community Games</title>
		<link>http://www.3dgameprogramming.net/2008/02/21/xbox-live-community-games/</link>
		<comments>http://www.3dgameprogramming.net/2008/02/21/xbox-live-community-games/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 08:02:22 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/2008/02/21/xbox-live-community-games/</guid>
		<description><![CDATA[The XNA team is delighted to announce the Xbox LIVE community games, scheduled for launch in the holiday 2008 season, with a beta coming in spring 2008. This offering gives the opportunity to share, peer review, download and play games &#8230; <a href="http://www.3dgameprogramming.net/2008/02/21/xbox-live-community-games/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The XNA team is delighted to announce the Xbox LIVE community games, scheduled for launch in the holiday 2008 season, with a beta coming in spring 2008.  This offering gives the opportunity to share, peer review, download and play games created by the community, for the community.  Read the FAQ for more details, or discuss in the special forum thread.</p>
<p><img src="http://creators.xna.com/Themes/default/images/Xbox_Live_Community_Games1.png" alt="Xbox LIVE Community Games" /></p>
<p>      <a href="http://forums.xna.com/ShowThread.aspx?PostID=46554">FAQ Link</a><br />
      <a href="http://forums.xna.com/46558/ShowThread.aspx">Forum Thread Discussion Link</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2008/02/21/xbox-live-community-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA_BUG : February 2008 XNA Contest</title>
		<link>http://www.3dgameprogramming.net/2008/02/01/xna_bug-february-2008-xna-contest/</link>
		<comments>http://www.3dgameprogramming.net/2008/02/01/xna_bug-february-2008-xna-contest/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 21:31:16 +0000</pubDate>
		<dc:creator>Brecht Kets - Microsoft XNA MVP</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.3dgameprogramming.net/2008/02/01/xna_bug-february-2008-xna-contest/</guid>
		<description><![CDATA[The XNA Belgian User Group organizes the February 2008 XNA Contest This contest is open for developers and designers, working on XNA Games. The development and demo can be done on a PC platform or XBOX 360. The participants can &#8230; <a href="http://www.3dgameprogramming.net/2008/02/01/xna_bug-february-2008-xna-contest/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.xnabug.net/">The XNA Belgian User Group</a> organizes <a href="http://www.xnabug.net/contest.htm">the February 2008 XNA Contest</a></p>
<p>This contest is open for developers and designers, working on XNA Games. The development and demo can be done on a PC platform or XBOX 360.<br />
The participants can form teams of 2 people working together. Participants have to be 16 years old at the days of the finals, but not older than 36 years (born between February 23, 1972 and February 23, 1992) AND live in Belgium.</p>
<p>The contest is based on a &#8216;starter kit&#8217;, consisting of a &#8216;nearly finished&#8217; game, build on top of XNA. The purpose of the contest is to extend this starter kit in the best and most creative way. The starter kit will be made available from February 1 on <a href="http://www.xnabug.net/starterkits.htm">http://www.xnabug.net/starterkits.htm</a><br />
Submissions will be judged on creativity, innovation and &#8216;playability&#8217; of the demo.</p>
<p><strong>To judge the submissions, participating teams need to:</strong><br />
- Enroll for the contest by mailing an enrollment form to [BRECHT at XNABUG dot NET]. The enrollment form is available here. The enrollment form has to be received by February 18 midnight.</p>
<p>- Prepare 2 &#8216;posters&#8217; explaining the submission. The posters have to be printed on A3 paper size. These posters will be used during round one on during the finals, February 23. Based on the posters and questions and answers, the jury will select the teams which will present and demo their submission.</p>
<p>- Prepare a presentation/demo of 10 minutes and 5 minutes of questions and answers. This demo and presentation will be done February 23 in front of the jury and the audience. It will be executed on the equipment of the participating team. The facility to project on a large screen will be provided by the organization.</p>
<p><strong>Judging criteria:</strong><br />
The submissions, posters and presentations/demo&#8217;s will be judged by a multidisciplinary team of gaming specialists., active in training, development, design and press. The judging criteria will be: |innovation|, |creativity| and |play, demo|.</p>
<p><strong>What can you win:</strong><br />
The winning team will receive an XBOX 360 elite for every participant (up to 2). Every team presenting / demo during the finals will receive an XNA Creators Club account and more.<br />
The finals will take place in the auditoria of Groep T, Campus Vesalius, Vesaliusstraat 13, 3000 Leuven (INFO).<br />
<strong><br />
For more information:</strong><br />
<a href="http://www.xnabug.net">http://www.xnabug.net</a><br />
<a href="http://www.microsoft.com/xna">http://www.microsoft.com/xna</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3dgameprogramming.net/2008/02/01/xna_bug-february-2008-xna-contest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

