<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6985766342586546951</id><updated>2026-08-23T09:43:50.603-07:00</updated><title type='text'>C# Tutorials</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-1575086906059824278</id><published>2030-02-19T10:10:00.000-08:00</published><updated>2013-05-05T14:30:18.360-07:00</updated><title type='text'>Introduction</title><content type='html'>Hello, my name is Marc and I will try to teach you the basics of &lt;b&gt;C#&lt;/b&gt; (pronounced C Sharp) using &lt;b&gt;Visual Studio 2010&lt;/b&gt; by creating easy-to-understand tutorials and by putting a link to every project&#39;s source code at the end of each tutorial&#39;s page. For most of the tutorials I will use &lt;b&gt;.NET Framework 2.0&lt;/b&gt;, but sometimes I will use other .NET Framework versions to show components such as &lt;b&gt;LINQ&lt;/b&gt;. &lt;br /&gt;
&lt;br /&gt;
The reason why I choose C# is because it is easy to learn thanks to the .NET Framework and the integrated development environment (IDE) Visual Studio. I started off with Visual Basic which might look like an easy start, because the language looks more like the English language instead of a cryptic programming language. This turned out badly for me when I had to program in PHP which required the oh-so-fun ; sign. I kept forgetting to use the ; sign in PHP and when I switched back to Visual Basic I kept using the ; sign when it obviously wasn&#39;t needed in that programming language and it would only generate errors. To make a long story short, in my opinion it&#39;s better to start with a cryptic programming language to avoid problems later.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRdDj5XNv0Og1nOBJWOdbvanJMgRLQzS1S9LTWD8R-zDJSqeesDO6N9Zngp06_SPLVF6QABrROKYt86D-N16ln0HUOXEk2oYqb8QnwuQ5c4ge2RRQlKoO0GEtJC573nr_ywXn_m3LXcXw/s1600/csharp_origin_transparent.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;245&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRdDj5XNv0Og1nOBJWOdbvanJMgRLQzS1S9LTWD8R-zDJSqeesDO6N9Zngp06_SPLVF6QABrROKYt86D-N16ln0HUOXEk2oYqb8QnwuQ5c4ge2RRQlKoO0GEtJC573nr_ywXn_m3LXcXw/s320/csharp_origin_transparent.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Your first question will probably be: &quot;Why is your blogspot URL so damn long?&quot;. This is because the first thing I learned about C# is that it was greatly influenced by C++ and that it was so good they wanted to call it C++++. The name was too long so they combined the four plusses to the # sign. That&#39;s the one thing that has stayed with me for so long that I decided to use it.&lt;br /&gt;
&lt;br /&gt;
The best tutorials are mostly written by the people that recently learned the subject, because they remember exactly where they had trouble with and where they had no trouble with. Unfortunately I didn&#39;t know that at the time I started learning C#, so I didn&#39;t put any effort in trying to memorise my problems. This is why your help is needed in order to make the tutorials as easy as possible by sending feedback to my email: &lt;b&gt;cplusplusplusplustutorials@hotmail.com&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Hopefully my tutorials will be of any use to you and I wish you good luck!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/how-to-get-started.html&quot;&gt;&amp;gt;&amp;gt; How To Get Started&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/1575086906059824278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/introduction.html#comment-form' title='34 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/1575086906059824278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/1575086906059824278'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/introduction.html' title='Introduction'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRdDj5XNv0Og1nOBJWOdbvanJMgRLQzS1S9LTWD8R-zDJSqeesDO6N9Zngp06_SPLVF6QABrROKYt86D-N16ln0HUOXEk2oYqb8QnwuQ5c4ge2RRQlKoO0GEtJC573nr_ywXn_m3LXcXw/s72-c/csharp_origin_transparent.png" height="72" width="72"/><thr:total>34</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-1674600665208729472</id><published>2012-06-29T12:11:00.000-07:00</published><updated>2012-06-29T12:11:20.811-07:00</updated><title type='text'>Polymorphism Interfaces</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFV25OSFVhZWpRMnc&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Polymorphism Interfaces Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Polymorphism&lt;/span&gt;&amp;nbsp;is used for converting from the derived class to the base class. The derived class is the class that&#39;s inheriting/implementing and the base class is the class that&#39;s being inherited/implemented. You can then of course only use the public methods, properties and global variables of the base class.&lt;br /&gt;
&lt;br /&gt;
This doesn&#39;t seem very exciting, but you can also convert the derived class to the base &lt;b&gt;interface. &lt;/b&gt;When done that, the interface object can all of a sudden be used to call methods and properties. You will be only able to use the methods and properties the interface has&lt;b&gt;, but the actual code being executed will be of the derived class.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Create a new console application called &quot;Polymorphism Tutorial&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ICiviliancode2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ICiviliancode2.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
I want to show you an example with the interface &quot;ICivilian&quot; and the classes &quot;Man&quot; and &quot;Woman&quot;. Add an interface called &quot;ICivilian&quot;, then add the following code to the interface:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
string Name&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;get;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;set;&lt;br /&gt;
}&lt;br /&gt;
void PayTaxes();&lt;/blockquote&gt;
Each civilian has a name and has a method to pay their taxes.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/womancode-1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/womancode-1.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add a new class called &quot;Woman&quot; and make it implement &quot;ICivilian&quot;, then add the following code to &quot;Woman&quot;:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
private string _name;&lt;br /&gt;
public string Name&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;get { return _name; }&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;set { _name = value; }&lt;br /&gt;
}&lt;br /&gt;
public void PayTaxes()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(&quot;Paying taxes&quot;);&lt;br /&gt;
}&lt;br /&gt;
public void NurseWound()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(&quot;Nursing wounds&quot;);&lt;br /&gt;
}&lt;/blockquote&gt;
The interface&#39;s methods are implemented in the &quot;Woman&quot; class with an extra method called &quot;NurseWounds&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mancode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mancode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now add a class called &quot;Man&quot; and make it implement &quot;ICivilian&quot; as well. Add the following code to the class &quot;Man&quot;:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
private string _name;&lt;br /&gt;
public string Name&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;get { return _name; }&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;set { _name = value; }&lt;br /&gt;
}&lt;br /&gt;
public void PayTaxes()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(&quot;Paying taxes&quot;);&lt;br /&gt;
}&lt;br /&gt;
public void FixCar()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(&quot;Fixing car&quot;);&lt;br /&gt;
}&lt;/blockquote&gt;
The method and property of the interface &quot;ICivilian&quot; have been implemented with an extra method called &quot;FixCar&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mainmethodcodepartone.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mainmethodcodepartone.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now to initialize the objects for &quot;Man&quot; and &quot;Woman&quot;, and to give them both a name in the &quot;Program&quot; class&#39; &quot;Main&quot; method:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Man man = new Man();&lt;br /&gt;
Woman woman = new Woman();&lt;br /&gt;
man.Name = &quot;Bob&quot;;&lt;br /&gt;
woman.Name = &quot;Sarah&quot;;&lt;/blockquote&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mainmethodcodeparttwo.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mainmethodcodeparttwo.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
All that&#39;s left is polymorphism, so add the following code to your &quot;Main&quot;:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
ICivilian civilianOne = man;&lt;br /&gt;
ICivilian civilianTwo = woman;&lt;/blockquote&gt;
Above code converts the &quot;Man&quot; object and &quot;Woman&quot; object to &quot;ICivilian&quot; objects. This can be done, because &quot;Man&quot; and &quot;Woman&quot; implemented &quot;ICivilian&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mainmethodcodepartthree.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mainmethodcodepartthree.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now to test the code, so you can see that the content of the properties and methods being called are actually of the derived class and not of the base interface. Not that it would be possible that the content would be of the interface, since interfaces can&#39;t have content. Add the following code to your &quot;Main&quot; method:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Console.WriteLine(civilianOne.Name);&lt;br /&gt;
Console.WriteLine(civilianTwo.Name);&lt;br /&gt;
civilianOne.PayTaxes();&lt;br /&gt;
civilianTwo.PayTaxes();&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;
You can try to call the methods &quot;FixCar&quot; and &quot;NurseWound&quot;, but &quot;ICivilian&quot; doesn&#39;t know these methods.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/consoleapp.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/consoleapp.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Run your application by pressing F5. The names of the &quot;ICivilian&quot; objects should be displayed with twice the text &quot;Paying taxes&quot;.&lt;br /&gt;
&lt;br /&gt;
I found it hard to make this tutorial, so it took longer than it normally does. If this tutorial is difficult to understand, then I want input at what part you are having trouble with. You can of course do this with every tutorial, but this is the first time I felt uncertain about a tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFV25OSFVhZWpRMnc&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Polymorphism Interfaces Project&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/1674600665208729472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/polymorphism-interfaces.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/1674600665208729472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/1674600665208729472'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/polymorphism-interfaces.html' title='Polymorphism Interfaces'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-2662518168438002344</id><published>2012-06-23T11:42:00.000-07:00</published><updated>2012-06-23T11:53:08.895-07:00</updated><title type='text'>Casting</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFUFBsdmliX0l2QU0&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Casting Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Casting is used for converting between data types.&lt;/b&gt; It&#39;s used for example when converting from a double to an integer. Doubles are data types that are used for numbers with decimals, like the number 25.5. If you cast this number to an int, then you will lose data, because an integer can&#39;t handle decimal numbers. Once you cast the double 25.5 to integer, the integer value will be 25. It will just cut the decimal off.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;You can&#39;t cast between every data type. &lt;/b&gt;It is not possible for example to cast from Random to Button. You can make casting between data types available in the classes you make yourself, but you will have to override something called a cast operator.&lt;br /&gt;
&lt;br /&gt;
There are two different types of casting:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Explicit casting&lt;/b&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Data will be lost when converting. For example when going from a decimal number (double) &amp;nbsp;to a non decimal number (int). In that case the decimal number will be lost.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b style=&quot;background-color: white;&quot;&gt;Implicit casting&lt;/b&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;No data will be lost when converting. If you convert from an integer to a double, then you will not lose any data, because a double is not smaller than an integer.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;br /&gt;
Create a new console application called &quot;&lt;b&gt;Casting Tutorial&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumbermethod.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumbermethod.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following method to your Program class:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public static void ShowNumber(int number)&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(number);&lt;br /&gt;
}&lt;/blockquote&gt;
I know that the public access modifier is unnecessary and that it should be private, but for this example it doesn&#39;t really matter. As you can see, this method writes a number on your console application.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumberwrong.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumberwrong.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now add the following code to your Main method:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
double doubleNumber = 25.5;&lt;br /&gt;
ShowNumber(doubleNumber);&lt;/blockquote&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumbererror.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumbererror.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
If you try to run your application right now, you will receive an error saying that the method ShowNumber&amp;nbsp;only accepts integers and that it can&#39;t convert a double to an integer. In order to fix it, you will have to use an &lt;b&gt;explicit cast&lt;/b&gt; for converting from a double to an integer.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumbercorrectly.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/shownumbercorrectly.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
In order to do so, you will have to replace your Main method&#39;s code with the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
double doubleNumber = 25.5;&lt;br /&gt;
int number = (int)doubleNumber;&lt;br /&gt;
ShowNumber(number);&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;
Now your double is converted to an integer using an explicit cast, but of course the decimal number has been lost. Next I want to show you how to use an implicit cast.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/implicitcasting.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/implicitcasting.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
For this example you will have to change the ShowNumber method&#39;s parameter from double to float and change your Main method so it will look like the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
static void Main(string[] args)&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int number = 25;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ShowNumber(number);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.Read();&lt;br /&gt;
}&lt;br /&gt;
public static void ShowNumber(&lt;b&gt;float &lt;/b&gt;number)&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(number);&lt;br /&gt;
}&lt;/blockquote&gt;
It seems like nothing is being cast, but the integer is actually converted to a float using an &lt;b&gt;implicit cast&lt;/b&gt;. You can still use an explicit cast, but why would you do that when you have the choice of using an implicit cast with no data being lost.&lt;br /&gt;
&lt;br /&gt;
Knowing the difference between an explicit cast and an implicit cast is nice, but I bet you just want to know how to convert between basic data types. That&#39;s why I made you a small list out of the many ways you can convert between certain basic data types:&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th width=&quot;9%&quot;&gt;Code&lt;/th&gt;
&lt;th width=&quot;15%&quot;&gt;Converts to&lt;/th&gt;
&lt;th width=&quot;30%&quot;&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*.ToString()&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;Almost every class in the .NET Framework has a ToString() method.&lt;/td&gt;
&lt;td&gt;&lt;i&gt;int number = 25;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;string message = number.ToString();
&lt;/i&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bool.Parse()&lt;/td&gt;
&lt;td&gt;Boolean&lt;/td&gt;
&lt;td&gt;Used to convert from almost every basic data type to boolean.&lt;/td&gt;
&lt;td&gt;&lt;i&gt;bool IsOn = bool.Parse(&quot;true&quot;);&lt;/i&gt;&lt;br /&gt;
---&lt;br /&gt;
&lt;i&gt;bool IsOn = bool.Parse(0); &lt;/i&gt;&lt;br /&gt;
&lt;i&gt;//0 converts to false, 1 converts to true
&lt;/i&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;int.Parse()&lt;/td&gt;
&lt;td&gt;Integer&lt;/td&gt;
&lt;td&gt;Used to convert from almost every basic data type to integer.&lt;/td&gt;
&lt;td&gt;&lt;i&gt;int number = int.Parse(&quot;25&quot;);&lt;/i&gt;&lt;br /&gt;
---&lt;br /&gt;
&lt;i&gt;int number = int.Parse(true); &lt;/i&gt;&lt;br /&gt;
&lt;i&gt;//false converts to 0, true converts to 1
&lt;/i&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;double.Parse()&lt;/td&gt;
&lt;td&gt;Double&lt;/td&gt;
&lt;td&gt;Used to convert from almost every basic data type to double.&lt;/td&gt;
&lt;td&gt;&lt;i&gt;doublenumber = double.Parse(&quot;25&quot;);&lt;/i&gt;&lt;br /&gt;
---&lt;br /&gt;
&lt;i&gt;doublenumber = double.Parse(true); &lt;/i&gt;&lt;br /&gt;
&lt;i&gt;//false converts to 0, true converts to 1
&lt;/i&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;int.TryParse()&lt;/td&gt;
&lt;td&gt;Integer&lt;/td&gt;
&lt;td&gt;This method puts the end result of the conversion in the out parameter and returns a boolean to indicate if the conversion has been successful. &lt;b&gt;If you try to use int.Parse(&quot;d&quot;); your application will crash, because &quot;d&quot; is not a valid number.&lt;/b&gt; This method will not crash your application.&lt;/td&gt;
&lt;td&gt;&lt;i&gt;int number;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;string message = &quot;Hello&quot;; &lt;/i&gt;&lt;br /&gt;
&lt;i&gt;bool isNumber = int.TryParse(message, &lt;b&gt;out &lt;/b&gt;number); &lt;/i&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
A lot of basic types, if not all, have a Parse&lt;span style=&quot;background-color: white;&quot;&gt;/TryParse&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;method. Don&#39;t think that the Parse/TryParse method only exist for bool, int and double. &quot;char.Parse()&quot; exists as well for example.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFUFBsdmliX0l2QU0&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Casting Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://cplusplusplusplus.blogspot.nl/2012/06/inheritance.html&quot; target=&quot;&quot;&gt;&lt;b&gt;&amp;gt;&amp;gt; Inheritance&lt;/b&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/2662518168438002344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/casting.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/2662518168438002344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/2662518168438002344'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/casting.html' title='Casting'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-8388741115516766206</id><published>2012-06-21T14:39:00.000-07:00</published><updated>2012-06-23T11:52:24.512-07:00</updated><title type='text'>Interfaces</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFeHYxdmw4S3N4WW8&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Interfaces Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are blueprints for classes to &lt;b&gt;implement.&lt;/b&gt;&amp;nbsp;With blueprints I mean the following: methods and properties can be declared in interfaces, &lt;b&gt;but they must contain no code. &lt;/b&gt;Global variables can&#39;t be declared in an interface.&lt;b&gt;&amp;nbsp;When a class implements an interface, it must contain every method and property that exists in the interface.&lt;/b&gt;&amp;nbsp;This must sound really useless, because why would you want a blueprint that classes can use when you can just type the methods and properties in the class without a blueprint.&lt;br /&gt;
&lt;br /&gt;
Interfaces are used for the following:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Polymorphism (There will be a tutorial about this later on)&lt;/li&gt;
&lt;li&gt;The developer can make &quot;rules&quot; in their software by forcing other developers (or himself/herself) to implement certain methods.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
For this tutorial I will only show you the second part of the list shown above, because the concept of polymorphism is a lot to process when you don&#39;t know what interfaces are yet. If by the end of this tutorial you are not convinced that interfaces are handy, then you will probably be convinced when you see what you can do with polymorphism. Don&#39;t worry, I didn&#39;t think much of interfaces at first either.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Create a new console application called &quot;Interfaces Tutorial&quot;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addinterface.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addinterface.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
Let&#39;s start by adding an interface. Click on &quot;Project&quot; in the menu (Next to File, Edit, View...) (&lt;b&gt;1&lt;/b&gt;) and then click &quot;Add New Item&quot; (&lt;b&gt;2&lt;/b&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Selectinterface.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Selectinterface.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Select &quot;Interface&quot; (&lt;b&gt;1&lt;/b&gt;), give it the name &quot;IAnimal&quot; (&lt;b&gt;2&lt;/b&gt;) and then click &quot;Add&quot; (&lt;b&gt;3&lt;/b&gt;). The first thing you will notice is that instead of it saying &quot;class IAnimal&quot;, it will say &quot;interface IAnimal&quot;. The reason why I choose the name &quot;IAnimal&quot; is because every interface within the .NET Framework starts with the I from Interface and I try to keep my code consistent.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/makeSoundmethodinterface.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/makeSoundmethodinterface.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following to your interface:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
void makeSound();&lt;/blockquote&gt;
This method has quite a few differences compared to a method in a class. First of all is that it has no access modifier, so no public, private, protected or internal. Second is that it has no code and no &quot;{ }&quot; signs. A method in a class doesn&#39;t end with a &quot;;&quot; sign either. This is what I meant with blueprint. It&#39;s just the data type for the return, the method&#39;s name and parameters. The code inside the method will be left&amp;nbsp;entirely&amp;nbsp;up to the developer that will implement the interface in a class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/MeowWoof.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/MeowWoof.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;(Honestly stolen from&amp;nbsp;&lt;a href=&quot;http://www.theverybestcats.blogspot.nl/&quot; target=&quot;_blank&quot;&gt;http://www.theverybestcats.blogspot.com/&lt;/a&gt;)&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;br /&gt;
Let&#39;s say that in a perfect world that every animal can make a sound. The reason why you would want to use an interface is because, for example, a cat makes a different sound than a dog. With an interface you give them the same method, but with different content.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;An interface object can not be initialized like a class object. &quot;IAnimal animal = new IAnimal();&quot; will &lt;span style=&quot;color: red;&quot;&gt;not&lt;/span&gt; work.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
Create a new class called &quot;Cat&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/implementianimal.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/implementianimal.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
In order for Cat to implement IAnimal, &quot; : IAnimal&quot; must be typed after &quot;class Cat&quot;, so it will look like the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
class Cat : IAnimal&lt;/blockquote&gt;
It looks exactly the same when inheriting a class, but now an interface is used. &lt;b&gt;You can implement and inherit at the same time by using the &quot;,&quot; sign.&lt;/b&gt; If you have a class called &quot;Creature&quot; it will look like this: &quot;class Cat : IAnimal, Creature&quot;. You can implement more than one interface in a class, unlike inheritance where a class can only inherit a maximum of one class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/errornotimplemented.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;56&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/errornotimplemented.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
If you try to run your application now, it will give you an error saying that Cat has not yet implemented the method &quot;makeSound()&quot; from the interface IAnimal.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/catcode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/catcode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following code in order to fix the error:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public void makeSound()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(&quot;Meow&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.ReadLine();&lt;br /&gt;
}&lt;/blockquote&gt;
Now the Cat class has implemented the &quot;makeSound()&quot; method and by doing that the error should be gone.&lt;br /&gt;
&lt;br /&gt;
Next I would like to show you that you can implement multiple interfaces at once.&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;Create a new interface called &quot;ICarnivore&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/carnivorecode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/carnivorecode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following to your ICarnivore interface:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
void eatMeat();&lt;/blockquote&gt;
Let&#39;s just say that every carnivore eats meat in a different way.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/multipleimplement.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/multipleimplement.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Switch back to your Cat class and add &quot;, ICarnivore&quot; to &quot;class Cat : IAnimal&quot;, so it looks like the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
class Cat : IAnimal, ICarnivore&lt;/blockquote&gt;
You still have to make Cat implement the &quot;eatMeat()&quot; method or the compiler will generate an error, so add the following method to Cat:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public void eatMeat()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.WriteLine(&quot;I eat meat like a cat&quot;);&lt;br /&gt;
}&lt;/blockquote&gt;
&amp;nbsp;Now you have implemented two interfaces in the same class. The only thing left to do is to actually use the Cat class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programcarnivoreanimalcode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programcarnivoreanimalcode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following code to your Program class&#39; Main method:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Cat cat = new Cat();&lt;br /&gt;
cat.eatMeat();&lt;br /&gt;
cat.makeSound();&lt;/blockquote&gt;
Press F5 to check your application and to test if everything works, then you&#39;re done!&lt;br /&gt;
&lt;br /&gt;
Interfaces will play a bigger role the more experience you have, but don&#39;t go overboard. I know a lot of programmers that use an interface for every class when it isn&#39;t&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;necessary. I hear a lot that interfaces are the new programming. That might be so, but I sometimes have the feeling that only students with no work experience say that. Then again, maybe I just don&#39;t understand this new programming.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFeHYxdmw4S3N4WW8&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Interfaces Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.nl/2012/06/references.html&quot;&gt;&amp;gt;&amp;gt; References&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/8388741115516766206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/interfaces.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8388741115516766206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8388741115516766206'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/interfaces.html' title='Interfaces'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-6149020477262800464</id><published>2012-06-20T10:56:00.000-07:00</published><updated>2012-06-21T14:51:26.404-07:00</updated><title type='text'>Inheritance</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFdG5uZ3lTeUx3a1U&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Inheritance Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Inheritance is used by a class to inherit another class its methods, properties and global variables. You can then add more methods, properties and&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;global&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;variables to the class that inherited the other class, so it can do the same and more.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/administratormemberguest.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;100&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/administratormemberguest.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
If inheritance did not exist, then there would be a lot of duplicate methods. Let&#39;s say that guests, members and administrators can post a comment on your website. All those classes would then require a method called &quot;makeComment(string commentText)&quot;. If you want to make a change to that method, then you will have to change the method in the guest, member and administrator class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/userinheritance.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;208&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/userinheritance.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
With inheritance you can make one class called user and let all the other classes inherit the user class. That way you only have to make changes to the makeComment method in the user class. Some people might think: &quot;But if I just change the makeComment method once and copy paste it in the other classes, I won&#39;t need inheritance!&quot;. My answer to that: &lt;b&gt;programmers should be so incredibly lazy, that even copy pasting code should look like too much trouble&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s start already by creating a new console application called &quot;Inheritance Tutorial&quot;. Add a new class to the project called &quot;&lt;b&gt;Woman&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/womancode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/womancode.jpg&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following code to the Woman class:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
private string _name;&lt;br /&gt;
public string Name&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;get { return _name; }&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;set { _name = value; }&lt;br /&gt;
}&lt;br /&gt;
private int _age;&lt;br /&gt;
public int Age&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;get { return _age; }&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;set { _age = value; }&lt;br /&gt;
}&lt;/blockquote&gt;
The Woman class now has two properties called &lt;b&gt;Name &lt;/b&gt;and &lt;b&gt;Age&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;span id=&quot;goog_322085447&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_322085448&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/derivewoman.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/derivewoman.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add a new class called &quot;&lt;b&gt;Mother&lt;/b&gt;&quot; and add the code &quot; : Woman&quot; after the text &quot;class Mother&quot;, so it will look like the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
class Mother : Woman&lt;/blockquote&gt;
&lt;b&gt;This makes the Mother class inherit all the&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;global&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp;variables, methods and properties from the Woman class.&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt; Mother now has the properties Age and Name, even though the properties are not visibly there in the Mother class file.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;You can only inherit a maximum of one class.&lt;/b&gt;&amp;nbsp;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basederived.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basederived.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
People in the IT world like to give names to everything, so they named the class that inherits another class the&amp;nbsp;&lt;b&gt;derived class&lt;/b&gt;&amp;nbsp;and they named the class that is inherited the &lt;b&gt;base class&lt;/b&gt;. Mother is the derived class and Woman is the base class in your software.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programagenamecode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programagenamecode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Type the following in your Program class&#39; main method to test if the inheritance&#39;s a success:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Mother mother = new Mother();&lt;br /&gt;
mother.Age = 12;&lt;br /&gt;
mother.Name = &quot;Mom&quot;;&lt;br /&gt;
Console.WriteLine(mother.Age);&lt;br /&gt;
Console.WriteLine(mother.Name);&lt;br /&gt;
Console.ReadLine();&lt;/blockquote&gt;
Press F5 to see it in action. As you can see, Mother now has the properties Age and Name. Next I want to show you that Mother can have the same methods, global variables and properties as Woman &lt;b&gt;and more.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/bedtimestory.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/bedtimestory.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Go back to your Mother class and add the following method:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public void TellBedtimeStory()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.Write(&quot;Once upon a time...&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Console.ReadLine();&lt;br /&gt;
}&lt;/blockquote&gt;
Now Mother has the methods, properties and global variables it inherited from Woman&lt;b&gt; plus its own method TellBedtimeStory().&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programmotherbedtime.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programmotherbedtime.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Go to your Program class and replace the code in its Main method with the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Mother mother = new Mother();&lt;br /&gt;
mother.TellBedtimeStory();&lt;/blockquote&gt;
Press F5 and you will see that it works like a charm. Last thing I would like to show is that when you initialize a Woman object, that you can&#39;t call the &quot;TellBedtimeStory()&quot; method from it.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programwomanbedtimecode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programwomanbedtimecode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following code to your Program class&#39; Main method:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Woman woman = new Woman();&lt;br /&gt;
woman.TellBedtimeStory();&lt;/blockquote&gt;
Press F5 and you will see that it won&#39;t work, because Woman does not have that method.&lt;br /&gt;
&lt;br /&gt;
For some people this tutorial must have been a little too detailed. That&#39;s because I wanted to show exactly&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;inheritance starts and ends.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFdG5uZ3lTeUx3a1U&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Inheritance Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.nl/2012/06/interfaces.html&quot;&gt;&amp;gt;&amp;gt; Interfaces&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/6149020477262800464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/inheritance.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6149020477262800464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6149020477262800464'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/inheritance.html' title='Inheritance'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-6198224173697968256</id><published>2012-06-19T08:24:00.000-07:00</published><updated>2012-06-19T13:47:29.592-07:00</updated><title type='text'>Properties</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFbktTbUxXb29IbkU&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Properties Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Properties are used as an alternative for the Get and Set methods that a lot of classes have. &lt;b&gt;This only involves the Get and Set methods where the Set method only has one parameter, but no data to return and where the Get method has no parameters, but does have data to return.&lt;/b&gt; In C# it&#39;s common that these Get/Set methods are all replaced by properties.&lt;br /&gt;
&lt;br /&gt;
As usual; start by creating a new console application and call it: &lt;b&gt;Properties Tutorial&lt;/b&gt;. Add a class to the project called: &lt;b&gt;Person&lt;/b&gt;. First I would like to show you what the application looks like with Get and Set methods and then replace them with a property.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/persongetsetcode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/persongetsetcode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following code to the Person class:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
private string _name;&lt;br /&gt;
public void SetName(string name)&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;_name = name;&lt;br /&gt;
}&lt;br /&gt;
public string GetName()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return _name;&lt;br /&gt;
}&lt;/blockquote&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programgetsetmethods.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programgetsetmethods.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you&#39;ve done that, add the following code to your Main function in your Program class:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Person person = new Person();&lt;br /&gt;
person.SetName(&quot;Bob&quot;);&lt;br /&gt;
Console.Write(person.GetName());&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;
Press F5 and you will see &quot;Bob&quot; on your console application. Next will be replacing the Get and Set methods with a property.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Personcode2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Personcode2.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Replace the Get and Set methods with the following code:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public string Name&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;get { return _name; }&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;set { _name = value; }&lt;br /&gt;
}&lt;/blockquote&gt;
Now you replaced the Get and Set methods with a property. The &lt;b&gt;get property accessor&lt;/b&gt; is used to return the value of the global _name variable, and the &lt;b&gt;set property accessor&lt;/b&gt; is used to assign a new value to the global _name variable. &lt;b&gt;Value &lt;/b&gt;is a keyword within C# that indicates the value/data when you call the set property accessor. So instead of a parameter, value is used.&lt;br /&gt;
&lt;br /&gt;
As you can see; the get property accessor contains the code of the GetName() method and the set property accessor contains the code of the SetName(string name) method.&lt;br /&gt;
&lt;br /&gt;
You also have to change the code in your Program class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programpropertycode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/programpropertycode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Replace the code in the Program class file with the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Person person = new Person();&lt;br /&gt;
person.Name = &quot;Bob&quot;;&lt;br /&gt;
Console.Write(person.Name);&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;
Only the way of approaching the data has changed:&amp;nbsp;&lt;b&gt;person.Name = &quot;Bob&quot;&lt;/b&gt; accesses the set property accessor and &lt;b&gt;Console.Write(person.Name)&lt;/b&gt; accesses the get property accessor of the Name property. You can remove a property accessor if you want to make it read-only or set-only.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Make a global variable public and you can approach it the same way as you approach a public property with a Get and a Set accessor&lt;/span&gt;, so why not just use a global variable? That&#39;s because it is common to only use global variables within its own class and the same reason why all global variables are private in professional software.&lt;br /&gt;
&lt;br /&gt;
Press F5 to check if the code is correctly implemented.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFbktTbUxXb29IbkU&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Properties Project&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/6198224173697968256/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/properties.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6198224173697968256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6198224173697968256'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/properties.html' title='Properties'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-2870058176101768654</id><published>2012-06-18T16:40:00.004-07:00</published><updated>2012-06-29T12:13:10.031-07:00</updated><title type='text'>References</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFcm1WaVVKVFZfcU0&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code References Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
References are used for using code that are outside the project. The most known example is a .dll file. In Visual Studio you can create a .dll file by creating a&lt;b&gt; Class Library &lt;/b&gt;project. It&#39;s basically an application without a user interface, so users can&#39;t interact with it. I personally use .dll files for code I use a lot for other projects. It is also used for logically separating code.&lt;br /&gt;
&lt;br /&gt;
I will use the words &lt;b&gt;project &lt;/b&gt;and &lt;b&gt;library &lt;/b&gt;intertwined, because when you develop a library it is a project within Visual Studio. This does not mean that every project is a library. I am implying that every library is a project when developing one in Visual Studio. By calling it a project, I hope you will understand that a library is nothing more than a collection of classes, just like a console application. The only difference is that a console application has a user interface and a library does not.&lt;br /&gt;
&lt;br /&gt;
Create a new console application called &lt;b&gt;Reference Tutorial&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/startreferences.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;352&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/startreferences.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To start off with the tutorial, I would like to point out that you already used references in the &quot;Hello World!&quot; tutorial. In the Solution Explorer (&lt;b&gt;1&lt;/b&gt;) you see all the references that are currently made in your current project. For example there is a project (&lt;span style=&quot;background-color: white;&quot;&gt;library)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;called &lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;System &lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;which has been made a reference to&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;and as you can see many more: System.Core, System.Data, etc... You can compare the project System with your current project. Your current project is called Reference Tutorial and the project that you are using outside your project is called System. The only difference is that you can&#39;t change the code that the project System contains, because Microsoft &amp;nbsp;does not like it when other people can see/change their code.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Just referencing it to your project is not enough in order to use the methods System can provide. You also have to point it out in the class its file (&lt;b&gt;2&lt;/b&gt;) if you want to use it in that specific class file. Yes, this means that you have to type &quot;using &amp;lt;project name&amp;gt;;&quot; in every class file you plan on using your outside project.&lt;br /&gt;
&lt;br /&gt;
As a summary and &lt;b&gt;the only things you have to do&lt;/b&gt;:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;You have to create a reference inside your project (&lt;b&gt;1&lt;/b&gt;)&lt;/li&gt;
&lt;li&gt;You also have to tell the compiler you are using that reference in every class file you are going to use the reference. (&lt;b&gt;2&lt;/b&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b&gt;References are basically a one sided relation between two projects. &lt;/b&gt;With a reference you use an outside project without the outside project knowing that you are using it. It&#39;s like me controlling the hand of a paralyzed person.&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;I am the current project and the paralyzed person is the outside project and I&#39;m using that person&#39;s hand.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;The paralyzed person also does not notice me using his hand.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addnewproject.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addnewproject.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Let&#39;s start by creating your own reference. First you will need to add a new project. You can do this by &lt;b&gt;right clicking&lt;/b&gt; on your solution in the Solution Explorer (&lt;b&gt;1&lt;/b&gt;) -&amp;gt; Add (&lt;b&gt;2&lt;/b&gt;) -&amp;gt; New Project (&lt;b&gt;3&lt;/b&gt;).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Projectselect.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Projectselect.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Once you&#39;ve done that; add a Class Library project by clicking on it (&lt;b&gt;1&lt;/b&gt;). Then fill in a name for the project: &lt;b&gt;Reference Library&lt;/b&gt; (&lt;b&gt;2&lt;/b&gt;). Click OK when you&#39;re done (&lt;b&gt;3&lt;/b&gt;). It&#39;s basically the same when you create a new Console Application. As you see you can also add a new console application to the solution.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addednewproject.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addednewproject.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;A Class Library project will be added to the solution. By default a class will also be added to the library, called Class1.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/calculatorcode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/calculatorcode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start by renaming the&amp;nbsp;&lt;b&gt;Class1 &lt;/b&gt;file&amp;nbsp;to &lt;b&gt;Calculator &lt;/b&gt;by right clicking Class1 and selecting&amp;nbsp;&lt;b&gt;Rename. S&lt;/b&gt;elect Yes if it asks if you also want to rename the class itself (&lt;b&gt;1&lt;/b&gt;).&amp;nbsp;Once you have done that, add the following code (&lt;b&gt;2&lt;/b&gt;):&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public int Sum(int a, int b)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;return a + b;&lt;br /&gt;
}&lt;/blockquote&gt;
In order to use the &lt;b&gt;Sum &lt;/b&gt;method in your Program class, in the Reference Tutorial project, a reference has to be made.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addreference.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addreference.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add a reference by &lt;b&gt;right clicking&lt;/b&gt; your Reference Tutorial project in the Solution Explorer (&lt;b&gt;1&lt;/b&gt;) and then clicking&amp;nbsp;&lt;b&gt;Add Reference&lt;/b&gt; (&lt;b&gt;2&lt;/b&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Referenceselect.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;337&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Referenceselect.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can add various kinds of references (&lt;b&gt;1&lt;/b&gt;):&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;.NET&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;The .NET Framework has a lot of libraries that you can use. System is one of them.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;COM&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Here you can find the libraries that applications you have installed&amp;nbsp;provide. For example I have VLC media player installed and I can use their libraries to create my own extended VLC media player.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;Browse&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;You can browse for files on your computer and select it if it is a valid library. This does not mean you can select and use a .dll file in the Windows folder. That is because some companies do not want other people to use their code. If you could, they wouldn&#39;t be able to make money!&lt;b&gt; If you build the Reference Library project, it creates a .dll file and you can select that file, but then you wouldn&#39;t be able to change the code that easily in the Reference Library.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;Projects&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Here you can select a project in your solution that you wish to create a reference to. &lt;b&gt;You can use almost ANY project type as a reference. This also means console applications.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div&gt;
Click on the tab Projects and select the Reference Library if it is not selected yet (&lt;b&gt;2&lt;/b&gt;) and then click OK (&lt;b&gt;3&lt;/b&gt;).&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addedreference.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Addedreference.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will now see that the reference has been added to your project in the Solution Explorer (&lt;b&gt;1&lt;/b&gt;). Go to your Program class (Program.cs) and add the following under &quot;using System.Text;&quot;:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
using Reference_Library;&lt;/blockquote&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Now a reference has been made in your project and in the Program class file.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Referencecode.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Referencecode.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Now add the following code:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Calculator calculator = new Calculator();&lt;br /&gt;
int sumOutcome = calculator.Sum(5, 4);&lt;br /&gt;
Console.Write(sumOutcome);&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;
As you can see, initializing an object and calling its method is the same with a reference.&lt;br /&gt;
&lt;br /&gt;
The problem of using an outside project is that you don&#39;t know the classes and methods it contains. Now you do, because you made it yourself. The Object Browser will show the classes and methods the outside projects contain. You can open the Object Browser by going to View -&amp;gt; Object Browser.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/objectbrowser.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/objectbrowser.jpg&quot; width=&quot;580&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
As you can see and already know, your outside project Reference Library has a class called Calculator with a method called Sum. This way you can also explore System and of course all the other references you made. Maybe you can find a reference in the COM tab of an application you like and use their library, which you can fiddle around with it. Just remember:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;You have to create a reference inside your project&lt;/li&gt;
&lt;li&gt;You also have to tell the compiler you are using that reference in every class file you are going to use the reference (using &amp;lt;project name/library name&amp;gt;;).&lt;/li&gt;
&lt;/ul&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFcm1WaVVKVFZfcU0&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code References Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://cplusplusplusplus.blogspot.nl/2012/06/polymorphism-interfaces.html&quot;&gt;&lt;b&gt;&amp;gt;&amp;gt; Polymorphism Interfaces&lt;/b&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/2870058176101768654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/references.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/2870058176101768654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/2870058176101768654'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/references.html' title='References'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-1377967698869688180</id><published>2012-06-18T11:30:00.000-07:00</published><updated>2012-06-18T11:46:47.519-07:00</updated><title type='text'>Manga Updater</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFR1MtVEJyNG0tcFU&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code MangaUpdater Project&lt;/a&gt;

&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFWlJyVTdTLVd6Tmc&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Setup MangaUpdater&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;This page will only inform you of the functionality of this application. Code will not be discussed on this page. The application will need to be run as admin and .NET Framework 4.0 has to be installed or the application will crash horribly, since I am a very lazy developer. &lt;span style=&quot;color: red;&quot;&gt;Use this application at your own risk.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
A few months ago I started to really like reading manga. I bookmarked every manga I liked and I also bookmarked every new chapter, so I knew where I left off. One month later I had so many bookmarks that I couldn&#39;t keep track of them. I also wanted to learn how to use &lt;b&gt;LINQ&lt;/b&gt;, so I thought it would be a nice idea to develop an application that could keep track of the manga I followed.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mangaupdater.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/mangaupdater.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
On a lot of websites it is possible to keep track of updates by reading their &lt;b&gt;RSS &lt;/b&gt;feed. Explained&amp;nbsp;simply: The RSS feed is a file accessible through a URL, for example:&amp;nbsp;&lt;a href=&quot;http://mangafox.me/rss/bleach.xml&quot;&gt;http://mangafox.me/rss/bleach.xml&lt;/a&gt;. Mangafox uses &lt;b&gt;XML &lt;/b&gt;as data representation. It&#39;s also possible to use JSON (and many more), but XML is most common.&amp;nbsp;RSS feeds are usually used for showing updates that have been made on the website. For example if you host a website that shows news, then you could update the RSS feed with every added news. The RSS feed would then contain the title of the news and the link to the webpage of the news.&lt;br /&gt;
&lt;br /&gt;
I figured it would be a good idea to revolve the application around RSS since Mangafox uses RSS and a lot of other manga hosts use RSS as well. When you add an RSS URL (&lt;b&gt;1&lt;/b&gt;), it loads the XML and reads the data it needs. For now I only use the title and the chapters of the manga.&lt;br /&gt;
&lt;br /&gt;
When a manga is added, it is shown in a list (&lt;b&gt;2&lt;/b&gt;). Every manga is sorted in alphabetical order. If the current chapter of the manga is not the last chapter, then it is colored red and put at the top of the list, else it is colored green and put at the bottom of the list. The selected manga gets a light blue background color and the current chapter is shown.&lt;br /&gt;
&lt;br /&gt;
I also added a feature that makes a screenshot of the current chapter&#39;s webpage (&lt;b&gt;3&lt;/b&gt;). This is very useful for people that have an awful memory, like me. All those&amp;nbsp;Japanese&amp;nbsp;names don&#39;t help with that fact either.&lt;br /&gt;
&lt;br /&gt;
The application looks for updates&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;for each manga&amp;nbsp;in their RSS feed&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;every 15 minutes&amp;nbsp;or when you press the&amp;nbsp;refresh&amp;nbsp;button. A balloon with the manga titles&amp;nbsp;of the manga that have new chapters&amp;nbsp;will appear near your system tray. The application will also look for updates when it has been minimized to the system tray.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFWlJyVTdTLVd6Tmc&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Setup MangaUpdater&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFR1MtVEJyNG0tcFU&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code MangaUpdater Project&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/1377967698869688180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/manga-updater.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/1377967698869688180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/1377967698869688180'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2012/06/manga-updater.html' title='Manga Updater'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-6746500474384698358</id><published>2011-03-12T17:02:00.000-08:00</published><updated>2011-08-23T10:16:28.607-07:00</updated><title type='text'>Multiple Processes</title><content type='html'>&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFNjgxMTNjYTQtMzJlMS00MDgyLWJiMDYtYzFkMzEwYWVhZmE1&amp;amp;export=download&amp;amp;authkey=COiVi7YH&amp;amp;hl=en&quot;&gt;Source Code MultipleProcesses Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Google Chrome uses a process for each tab. This way the crashed tab won&#39;t make the other tabs crash. This example application contains a child application called &quot;ChildApplication.exe&quot;. This way you can put multiple child applications in your parent application.&lt;br /&gt;
&lt;br /&gt;
The child application will be split from the parent application when the parent application crashes. Personally I think it would be hard to make the parent crash, because all it does is containing child applications.&lt;br /&gt;
&lt;br /&gt;
I don&#39;t know for sure if the parent application is actually waiting for the child application to start first, because under the .NET Framework 2.0 the whole application wouldn&#39;t work. Only the child application would start. This is the reason why the application is using the &lt;b&gt;.NET Framework 4.0&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
To simulate a crash just create a button and put &quot;throw new Exception();&quot; in the button its click event.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFNjgxMTNjYTQtMzJlMS00MDgyLWJiMDYtYzFkMzEwYWVhZmE1&amp;amp;export=download&amp;amp;authkey=COiVi7YH&amp;amp;hl=en&quot;&gt;Source Code MultipleProcesses Project&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/6746500474384698358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/03/multiple-processes.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6746500474384698358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6746500474384698358'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/03/multiple-processes.html' title='Multiple Processes'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-2214193832630211715</id><published>2011-03-12T15:26:00.000-08:00</published><updated>2012-06-19T08:25:30.527-07:00</updated><title type='text'>Classes</title><content type='html'>&lt;b&gt;Classes&lt;/b&gt; are used to split your application into logical parts, so your code is easier to oversee. You can for example split a warship into several parts: weapons, ship, people and etc. In code you will have three classes called: &quot;Weapon&quot;, &quot;Ship&quot; and &quot;People&quot;. The class ship will then hold an array of weapons and people. You should first write down all the names of the classes with its methods that are logical for your application and then start coding. I bet you won&#39;t in the beginning, because coding is way too fun. I thought so too in the beginning, but now I like to predict how my application will look like in the end more.&lt;br /&gt;
&lt;br /&gt;
Enough small talk. Start a new console application called &quot;Classes&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classesaddclass.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classesaddclass.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Create a new class by clicking on Project -&amp;gt; Add Class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classescreateclassview.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;240&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classescreateclassview.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Select the template &quot;Class&quot;, fill in the name &quot;View&quot; and press Add.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classesviewcreated.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classesviewcreated.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
A new file has been created in your project and it&#39;s called &quot;View.cs&quot; which can be seen in your solution explorer. The file has been opened and you can see the contents in your text editor.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Classesconstructor.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/Classesconstructor.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Add the following code to your &quot;View&quot; class:&lt;br /&gt;
&lt;blockquote&gt;
public View()&lt;br /&gt;
{&lt;br /&gt;
Console.Write(&quot;I&#39;m alive!&quot;);&lt;br /&gt;
Console.ReadLine();&lt;br /&gt;
}&lt;/blockquote&gt;
&quot;public View()&quot; is not a method, it&#39;s a &lt;b&gt;constructor&lt;/b&gt;. It must have the same name as the class and it mustn&#39;t have a return data type. The constructor is called when the class has been &lt;b&gt;instantiated &lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/initializationview.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/initializationview.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Switch back to the &quot;Program.cs&quot; file and create an instance of the class by typing:&lt;br /&gt;
&lt;blockquote&gt;
View view = new View();&lt;/blockquote&gt;
Now the class has been instantiated and the constructor will be called when running your application. Note that the instance &quot;view&quot; of the class &quot;View&quot; could&#39;ve easily been called anything. The instance &quot;view&quot; doesn&#39;t need to be the same name as the class in lowercase. Press F5 on your keyboard to run your application now and &quot;I&#39;m alive!&quot; should be shown on your screen. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/createmethodshowoutput2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/createmethodshowoutput2.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Go to your class &quot;View&quot; and add the following method:&lt;br /&gt;
&lt;blockquote&gt;
public void ShowOutput(string text)&lt;br /&gt;
{&lt;br /&gt;
Console.Write(text);&lt;br /&gt;
Console.Read();&lt;br /&gt;
}&lt;/blockquote&gt;
The access modifier needs to be &quot;public&quot;, because you&#39;re going to call the &quot;ShowOutput&quot; method from the class where you instantiated the &quot;View&quot; class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classcallmethodshowoutputview.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classcallmethodshowoutputview.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Back to your &quot;Program&quot; class again. To call the &quot;ShowOutput&quot; method in the &quot;View&quot; class you will have to type the following below &quot;View view = new View();&quot;:&lt;br /&gt;
&lt;blockquote&gt;
view.ShowOutput(&quot;Hello World!&quot;);&lt;/blockquote&gt;
Press F5 on your keyboard and you should see &quot;Hello World!&quot; on your screen after pressing enter once, because your constructor has a &quot;Console.ReadLine();&quot; and your application executes that first.&lt;br /&gt;
&lt;br /&gt;
Use classes to give your application a logical structure. Try to divide classes in how you would do in real life. If you create a game tic tac toe and you want to check if someone made a valid move, then for example create a class called referee.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFZWViMDVjNmItYTY3NC00NWIxLTlmZDctMGJmZDg2YjcwNWIx&amp;amp;export=download&amp;amp;authkey=CKXU1tgM&amp;amp;hl=en&quot;&gt;Source Code Classes Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.nl/2012/06/properties.html&quot;&gt;&amp;gt;&amp;gt; Properties&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/2214193832630211715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/03/classes.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/2214193832630211715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/2214193832630211715'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/03/classes.html' title='Classes'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-7945529471591256144</id><published>2011-02-28T07:33:00.000-08:00</published><updated>2011-08-23T10:16:45.729-07:00</updated><title type='text'>Switch Statements</title><content type='html'>If statements are great for making choices, but what if you have a lot of choices? A traffic light has three colors: red, orange and green. You&#39;ll have to make two if statements and one else statement. For this example it isn&#39;t a lot, but what if we want to make choices between all traffic signs? That requires a lot more if statements and that would make your code messy. There is a statement that makes choosing between a lot of options less messy and it&#39;s called the &lt;b&gt;switch statement&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Start a new project called &quot;SwitchStatements&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/switchstatementsexplained.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/switchstatementsexplained.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Add the following code to your &quot;Main&quot; method:&lt;br /&gt;
&lt;blockquote&gt;string currentStatusTrafficLight = &quot;red&quot;;&lt;br /&gt;
switch (currentStatusTrafficLight)&lt;br /&gt;
{&lt;br /&gt;
case &quot;green&quot;:&lt;br /&gt;
Console.Write(&quot;The traffic light is showing green&quot;);&lt;br /&gt;
break;&lt;br /&gt;
case &quot;orange&quot;:&lt;br /&gt;
Console.Write(&quot;The traffic light is showing orange&quot;);&lt;br /&gt;
break;&lt;br /&gt;
case &quot;red&quot;:&lt;br /&gt;
Console.Write(&quot;The traffic light is showing red!&quot;);&lt;br /&gt;
break;&lt;br /&gt;
}&lt;br /&gt;
Console.ReadLine();&lt;/blockquote&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/switchstatementsexplainedexample.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;250&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/switchstatementsexplainedexample.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
A switch statement like any other code is read from top to bottom. Your application starts with &quot;switch (currentStatusTrafficLight)&quot;. &quot;Red&quot; is used for this example, so it will compare each case with &quot;Red&quot;. &lt;br /&gt;
&lt;br /&gt;
First up is the case &quot;green&quot;. The string &quot;red&quot; is not equal to the string &quot;green&quot;, so it will not execute the code &quot;Console.Write(&quot;The traffic light is showing green&quot;);break;)&quot;. &lt;br /&gt;
&lt;br /&gt;
Next up is the case &quot;orange&quot;. The string &quot;red&quot; is not equal to orange and like last time that means that the code &quot;Console.Write(&quot;The traffic light is showing orange&quot;);break&quot; will not be executed. &lt;br /&gt;
&lt;br /&gt;
Your last case is &quot;red&quot;. The string &quot;red&quot; is equal to &quot;red&quot;, so the code &quot;Console.Write(&quot;The traffic light is showing red!&quot;);break;&quot; will get executed. &lt;br /&gt;
&lt;br /&gt;
&quot;break&quot; will make your application jump out your switch statement, because you don&#39;t want it to compare &quot;red&quot; with any more cases. Not that it matters in this example, because there aren&#39;t any more cases to compare &quot;red&quot; with. The keyword &quot;break&quot; will also make your application jump out of a loop. This is useful for when you want to search a name in an array and when you found the name you can jump out of the loop, so it doesn&#39;t continue the loop when it isn&#39;t necessary.&lt;br /&gt;
&lt;br /&gt;
Every case is basically an if statement. Take the following example condition in an if statement: &quot;(&quot;red&quot; == &quot;green&quot;);&quot;.  The string &quot;red&quot; is what you put in the switch: &quot;switch (&quot;red&quot;)&quot;. After that you make a case for the string &quot;green&quot;: &quot;case &quot;green&quot;:&quot;. Your application compares &quot;red&quot; and &quot;green&quot; like in the if statement its condition.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFZDI5NzRlMTUtYzA1Yi00OTc4LWFhMWUtODliZmQzZDkzYzUw&amp;export=download&amp;authkey=CLjFitIC&amp;hl=en&quot;&gt;Source Code SwitchStatements Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/methods.html&quot;&gt;&amp;gt;&amp;gt; Methods&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/7945529471591256144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/switch-statements.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/7945529471591256144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/7945529471591256144'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/switch-statements.html' title='Switch Statements'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-8811545550620722842</id><published>2011-02-26T16:48:00.000-08:00</published><updated>2011-08-23T10:16:49.200-07:00</updated><title type='text'>If Else Statements</title><content type='html'>&lt;b&gt;If statements&lt;/b&gt;&amp;nbsp;in C# and a lot of other programming languages are used to make choices in your application. Us humans make a lot of choices in life. &lt;b&gt;If&lt;/b&gt; you have no ham, &lt;b&gt;then&lt;/b&gt; you go to the supermarket to buy ham. You don&#39;t want to buy ham if you already have a bunch at home.&lt;br /&gt;
&lt;br /&gt;
Time to show you an example, but first you&#39;ll need to create a new console application called &quot;IfStatements&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/IfStatementsexplained.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/IfStatementsexplained.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The following code will be used for the explanation:&lt;br /&gt;
&lt;blockquote&gt;//We have a lot of ham, so we don&#39;t need more&lt;br /&gt;
bool inNeedOfHam = false;&lt;br /&gt;
&lt;br /&gt;
if (inNeedOfHam == true)&lt;br /&gt;
{&lt;br /&gt;
Console.Write(&quot;Buy ham!&quot;);&lt;br /&gt;
}&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;&lt;br /&gt;
The variable &quot;inNeedOfHam&quot; will decide if you need ham and for this example you don&#39;t need any, so it&#39;s set to false.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ifstatementhamexplained3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;143&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ifstatementhamexplained3.jpg&quot; width=&quot;427&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&quot;(inNeedOfHam == true)&quot; is the &lt;b&gt;condition&lt;/b&gt; of the if statement and the signs &quot;==&quot; are the &lt;b&gt;comparison&lt;/b&gt;. It will compare the variable &quot;inNeedOfHam&quot; that holds the data false with the data true. False is not equal to true, so the code &quot;Console.Write(&quot;Buy ham!&quot;);&quot; will not be executed. If you&#39;re stubborn, then press F5 on your keyboard (See what I did?). Memorise that &quot;==&quot; will compare data and &quot;=&quot; will assign data.&lt;br /&gt;
&lt;br /&gt;
You will use comparisons for every if statement and &quot;==&quot; is one of many:&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;==&lt;/b&gt; - Exactly equal to&lt;br /&gt;
&lt;b&gt;&amp;gt;&lt;/b&gt; - Greater than&lt;br /&gt;
&lt;b&gt;&amp;lt;&lt;/b&gt; - Less than &lt;br /&gt;
&lt;b&gt;&amp;gt;=&lt;/b&gt; - Greater than or equal to&lt;br /&gt;
&lt;b&gt;&amp;lt;=&lt;/b&gt; - Less than or equal to&lt;br /&gt;
&lt;b&gt;!=&lt;/b&gt; - Not equal to&lt;/blockquote&gt;Memorising these will prove useful as almost every application will contain one or more comparisons.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ifelsestatementexplained.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ifelsestatementexplained.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
For the next example you will turn your &quot;if statement&quot; into an &quot;if else statement&quot;, so it will look like the following:&lt;br /&gt;
&lt;blockquote&gt;if (inNeedOfHam == true)&lt;br /&gt;
{&lt;br /&gt;
Console.Write(&quot;Buy ham!&quot;);&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
Console.Write(&quot;I don&#39;t need ham&quot;);&lt;br /&gt;
}&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ifelsestatementhamexplainedJPG.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ifelsestatementhamexplainedJPG.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The else statement will always have the opposite comparison to that of the if statement. In other words: the if statement has the condition &quot;If false is equal to true&quot;, so the else statement has the condition &quot;If false is not equal to true&quot;. The else statement its condition is true, because false is not equal to true. This means that the code &quot;Console.Write(&quot;I don&#39;t need ham&quot;);&quot; will be executed and &quot;I don&#39;t need ham&quot; will be written on your screen. Press F5 on your keyboard to check.&lt;br /&gt;
&lt;br /&gt;
The same can be done for any other data type. An example condition &quot;(5 &amp;lt; 10)&quot; will check if the number 5 is smaller than 10. This condition is true, because 5 is smaller than 10.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFOTlkZjMyN2EtZDNmYy00ZjY4LTg4ZjYtOGU0Y2RiYjE2OTJm&amp;amp;export=download&amp;amp;authkey=CP2i_bgM&amp;amp;hl=en&quot;&gt;Source Code IfStatements Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/arrays.html&quot;&gt;&amp;gt;&amp;gt; Arrays And Loops&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/8811545550620722842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/if-statements.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8811545550620722842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8811545550620722842'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/if-statements.html' title='If Else Statements'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-6799351408259543384</id><published>2011-02-24T12:34:00.001-08:00</published><updated>2011-09-09T10:55:52.974-07:00</updated><title type='text'>Arrays And Loops</title><content type='html'>Arrays are variables that can hold a list of data, instead of one. After all it would be annoying to create 20 variables to hold a list of numbers.&lt;br /&gt;
&lt;br /&gt;
First create a new project called &quot;ArraysAndLoops&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ArraysAndLoopsbeginning.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ArraysAndLoopsbeginning.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Start by typing:&lt;br /&gt;
&lt;blockquote&gt;int[] listOneOfNumbers = new int[3] {25,31,43};&lt;br /&gt;
int[] listTwoOfNumbers = new int[3];&lt;br /&gt;
listOneOfNumbers[0] = 25;&lt;br /&gt;
listOneOfNumbers[1] = 31;&lt;br /&gt;
listOneOfNumbers[2] = 43;&lt;/blockquote&gt;You know that every variable needs a data type. Every array also needs a data type and in this case it will be of the basic data type int. The rule in C# is to put the &quot;[]&quot; signs after the data type to make it an array. The &quot;new int&quot;  is to create the array with the basic data type and give it a spot in the memory. &quot;[3]&quot; shows that your array will hold 3 &lt;b&gt;elements&lt;/b&gt; of data. Try to assign data to a non-existent fourth element and your application will crash. There are two ways to assign data to each element and both are correct, so just pick one. Arrays begin with element #0 and &lt;b&gt;not&lt;/b&gt; with element #1.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/declaringarraywaynr1-2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;240&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/declaringarraywaynr1-2.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&quot;int[] listOneOfNumbers = new int[3] &lt;b&gt;{25,31,43}&lt;/b&gt;;&quot; will assign data to each element and can only be used when creating an array. The following numbers will be assigned to each a specific element based on the order of the numbers in the array: 25, 31 and 43. The number 25 will be assigned to element #0, 31 to element #1 and 43 to element #2.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/declaringarraywaynr2-3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;287&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/declaringarraywaynr2-3.jpg&quot; width=&quot;453&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;blockquote&gt;int[] listTwoOfNumbers = new int[3];&lt;br /&gt;
listOneOfNumbers[0] = 25;&lt;br /&gt;
listOneOfNumbers[1] = 31;&lt;br /&gt;
listOneOfNumbers[2] = 43;&lt;/blockquote&gt;Above code will first create an array with only 0s as data in its elements. Then you assign data to each element separately. You start with element #0 and end with element #2. In total there are 3 elements to assign data to, just like you typed when you created your array.&lt;br /&gt;
&lt;div&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/loopstexteditor.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/loopstexteditor.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You want to read all the elements in the array and want to show them on your screen. This is done by using a &lt;b&gt;loop &lt;/b&gt;that goes through every element in the array. Add the following code below &quot;listOneOfNumbers[2] = 43;&quot;:&lt;br /&gt;
&lt;blockquote&gt;for (int i = 0; i &amp;lt; listOneOfNumbers.Length; i++)&lt;br /&gt;
{&lt;br /&gt;
Console.Write(listOneOfNumbers[i] + &quot;\n&quot;);&lt;br /&gt;
}&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;&lt;br /&gt;
&lt;div&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/forloopexplained.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;96&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/forloopexplained.jpg&quot; width=&quot;431&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;A &lt;b&gt;for&lt;/b&gt; loop consists out of 3 parts. First you need to &lt;b&gt;initialize&lt;/b&gt; a variable. This variable is used to check how many times your code in the loop has been repeated. &lt;br /&gt;
&lt;br /&gt;
The second part is the &lt;b&gt;condition&lt;/b&gt;. Your application checks the condition if it still applies every time it loops from the beginning. In the code you just added the condition is &quot;i &amp;lt; 3&quot; (Your array has 3 elements), so your application loops as long as the variable &quot;i&quot; is smaller than 3. This means that the loop will go through the numbers 0, 1 and 2.   The third and last part is the &lt;b&gt;step&lt;/b&gt;. This part increments your variable &quot;i&quot; every time it loops or else the condition would be useless, because the variable &quot;i&quot; would stay on 0.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/arrayexample.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;431&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/arrayexample.jpg&quot; width=&quot;490&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The first time your loop its variable &quot;i&quot; will contain the number 0. This is perfect, because you need to read element #0 in your loop. After reading the element and getting the data your application will write the number 25 on your screen. The loop is now done and will increment the variable &quot;i&quot; in the step part of the loop. After that it will check if the condition is still true. The variable &quot;i&quot; now holds the number 1. The loop will continue,  because 1 is smaller than 3.&lt;br /&gt;
&lt;br /&gt;
Now your loop&#39;s variable &quot;i&quot; holds the number 1 and it will execute the code in the loop again. It will now read element #1 and write the number 31 on your screen. It will increment the variable &quot;i&quot; again and will now check if 2 is smaller than 3. It is, so it will loop again.&lt;br /&gt;
&lt;br /&gt;
Variable &quot;i&quot; now holds the number 2, so it will read element #2 and write the number 43 on your screen. After incrementing the variable &quot;i&quot; again it will check the condition. 3 is not smaller than 3, so the loop stops. This means that &quot;Console.Read();&quot; will be executed and this is where your application ends.&lt;br /&gt;
&lt;br /&gt;
Run your application by pressing F5 on your keyboard and you should see the numbers 25, 31 and 43 on your screen.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFZDI5NzRlMTUtYzA1Yi00OTc4LWFhMWUtODliZmQzZDkzYzUw&amp;export=download&amp;authkey=CLjFitIC&amp;hl=en&quot;&gt;Source Code ArraysAndLoops Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/switch-statements.html&quot;&gt;&amp;gt;&amp;gt; Switch Statements&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/6799351408259543384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/arrays.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6799351408259543384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6799351408259543384'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/arrays.html' title='Arrays And Loops'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-4580997029364774169</id><published>2011-02-23T14:10:00.000-08:00</published><updated>2011-08-23T10:16:56.913-07:00</updated><title type='text'>Basic Calculations</title><content type='html'>Everyone has a calculator nowadays. There&#39;s probably a calculator on your computer right now. If you don&#39;t then it won&#39;t be hard to make a basic calculator yourself, but before you do that you&#39;ll need to know how to add, extract, multiply and divide in C#.&lt;br /&gt;
&lt;br /&gt;
First create a new console application called &quot;BasicCalculations&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basiccalculationsadding2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basiccalculationsadding2.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Start by typing:&lt;br /&gt;
&lt;blockquote&gt;int outcomeByAdding = 5 + 5;&lt;br /&gt;
Console.Write(outcomeByAdding);&lt;br /&gt;
Console.Read();&lt;/blockquote&gt;The variable &quot;outcomeByAdding&quot; will hold the number 10 after calculating 5 + 5. You put the variable &quot;outcomeByAdding&quot; as the parameter for the &quot;Write&quot; method, so you will see 10 on your screen when running your application by pressing F5 on your keyboard.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basiccalculationseverything5.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basiccalculationseverything5.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can do the same for subtracting, multiplying and dividing. Add the following to your code below &quot;int outcomeByAdding = 5 + 5;&quot;: &lt;br /&gt;
&lt;blockquote&gt;int outcomeBySubtracting = 10 - 5;&lt;br /&gt;
int outcomeByMultiplying = 5 * 2;&lt;br /&gt;
int outcomeByDividing = 10 / 2;&lt;br /&gt;
&lt;br /&gt;
Console.Write(outcomeBySubtracting + &quot;\n&quot;);&lt;br /&gt;
Console.Write(outcomeByMultiplying + &quot;\n&quot;);&lt;br /&gt;
Console.Write(outcomeByDividing + &quot;\n&quot;);&lt;/blockquote&gt;Putting &quot;outcomeBySubtracting + &quot;\n&quot;&quot; will combine those two. If &quot;\n&quot; was of the basic data type int, then it would add those two numbers. In this case one of the two data is of the basic data type string, so it will combine the two data. &quot;\n&quot; means &quot;new line&quot; and that will make your console application start on a new line. Run your application now and you should see the outcome of all the four calculations.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/addbyvariable2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/addbyvariable2.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
If you want to add the number 12 to the variable &quot;outcomeByAdding&quot;, so it will hold the number 17 won&#39;t suffice by typing: &quot;outcomeByAdding + 12;&quot;. You will have to type &quot;outcomeByAdding = outcomeByAdding + 12;&quot; below &quot;int outcomeByAdding = 5 + 5;&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/stepscalculating.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;168&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/stepscalculating.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Your application will first add the number 10 (the number assigned to your variable) to the number 12 and then assign the number 22 to your variable &quot;outcomeByAdding&quot;. You will now see the number 22 instead of the number 10 when you run your application. Instead of typing &quot;outcomeByAdding = outcomeByAdding + 12;&quot; you can also type &quot;outcomeByAdding += 12;&quot;. It does the exact same thing, but the full presentation was needed for the explanation. The same can be done with &quot;*&quot;, &quot;/&quot; and &quot;-&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basiccalculationsincrement2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/basiccalculationsincrement2.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Incrementing can be done by putting two &quot;+&quot; signs before or after a variable. For example the variable &quot;outcomeByAdding&quot; will look like &quot;outcomeByAdding++;&quot;. Incrementing by typing &quot;outcomeByAdding++;&quot; is the same as &quot;outcomeByAdding = outcomeByAdding + 1;&quot;. This will assign the number 23 (22 + 1) to the variable &quot;outcomeByAdding&quot;. Decrementing is also a possibility by typing &quot;outcomeByAdding--;&quot; which is the same as &quot;outcomeByAdding = outcomeByAdding - 1;&quot;. No, &quot;outcomeByAdding**&quot; or &quot;outcomeByAdding//&quot; won&#39;t work.&lt;br /&gt;
&lt;br /&gt;
That&#39;s it, basic calculations. You should memorise that calculations are done first and the outcome assigned to the variable.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFMWZiYzE4OGItNzBmOS00MjA0LThhYTYtZDAxOWU3MWE1YjE5&amp;export=download&amp;authkey=CJGtvJQJ&amp;hl=en&quot;&gt;Source Code BasicCalculations Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/if-statements.html&quot;&gt;&amp;gt;&amp;gt; If Else Statements&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/4580997029364774169/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/basic-calculations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/4580997029364774169'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/4580997029364774169'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/basic-calculations.html' title='Basic Calculations'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-6291001405637215161</id><published>2011-02-21T17:16:00.000-08:00</published><updated>2011-08-23T10:17:01.286-07:00</updated><title type='text'>Methods</title><content type='html'>Methods are used to make your applications clean or it would be one big code fest. It&#39;s also used when you need a piece of code multiple times, so you don&#39;t have to copy paste the same piece of code over and over.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s begin by creating a new console application called &quot;Methods&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/methodsdosomething.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1229.photobucket.com/albums/ff489/cplusplusplusplustutorials/methodsdosomething.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Create the method &quot;private static void ShowHelloWorld(){ }&quot; below your &quot;Main&quot; method. Type in your new method the code &quot;Console.Write(&quot;Hello World!&quot;);&quot; and &quot;Console.Read();&quot; like you did on your &quot;Hello World&quot; project. This should show the exact same as your old &quot;Hello World&quot; project when you run it by pressing F5 on your keyboard. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/methodexplained2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;142&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/methodexplained2.jpg&quot; width=&quot;412&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
A method consists of an &lt;b&gt;access modifier&lt;/b&gt;, a &lt;b&gt;modifier&lt;/b&gt; (access modifiers are part of modifiers), a &lt;b&gt;return data type&lt;/b&gt; and a &lt;b&gt;name&lt;/b&gt; (Yes, I did just make &quot;name&quot; bold to give it an extra effect). &lt;br /&gt;
&lt;br /&gt;
An access modifier exists to give your method an access level. There are four access modifiers in C#:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Private&lt;/b&gt; : The method can only be called within its own class&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Public &lt;/b&gt;: The method can always be called&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Internal&lt;/b&gt; : The method can only be called in its own project&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Protected &lt;/b&gt;: The method can only be called within its own class and classes that are derived from that class&lt;/li&gt;
&lt;/ul&gt;The fact that you can use the &quot;Write&quot; method from the class &quot;Console&quot; means the &quot;Write&quot; method is public. Your method &quot;ShowHelloWorld&quot; is private, so you won&#39;t be able to use it outside your &quot;Program&quot; class, because you don&#39;t have to in this case.&lt;br /&gt;
&lt;br /&gt;
There are a lot of modifiers: abstract, const, event, extern, override, readonly, sealed, static, unsafe, virtual and volatile. The only reason the method &quot;ShowHelloWorld&quot; is static is because it&#39;s being called from a static method &quot;Main&quot;. If the method wasn&#39;t static, then calling the method &quot;ShowHelloWorld&quot; would be a bit harder, because of the method &quot;Main&quot; being static. The method &quot;Main&quot; is static, because there should be only one. All the modifiers will be discussed at a certain point, but the modifiers will be too much to explain right now.&lt;br /&gt;
&lt;br /&gt;
Methods can return data and the return data type defines what kind of data will be returned. In your method &quot;ShowHelloWorld&quot; the return data type is void, because the method is for showing something and not for returning something.&lt;br /&gt;
&lt;br /&gt;
Naming a method is very important. You should give it a name that describes its functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/calculateprice3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/calculateprice3.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Imagine that you work at a computer store and your manager wants to calculate the &lt;b&gt;price&lt;/b&gt; of a new computer mouse based on the &lt;b&gt;costs &lt;/b&gt;of &lt;b&gt;5 dollars&lt;/b&gt;. Your manager tells you that the price is calculated by multiplying the costs by 2, dividing that by 5, adding that up by 2 and then subtracting 2 of that (Your manager isn&#39;t very smart). First you&#39;ll need a method: &lt;br /&gt;
&lt;blockquote&gt;private static int CalculatePrice(int costs)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
}&lt;/blockquote&gt;You want the method to return the price by calculating the costs and that&#39;s why it has a &lt;b&gt;parameter&lt;/b&gt; &quot;int costs&quot; which will be 5 dollars in this example and a return basic data type int (int is the basic data type of &quot;price&quot; which we will return). Parameters have a data type, so that means your method &quot;CalculatePrice&quot; won&#39;t accept data of the basic data type string &quot;Hello World!&quot; when it has a basic data type int.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/overloading2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;80&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/overloading2.jpg&quot; width=&quot;270&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Most methods have parameters. The method &quot;Write&quot; of the class &quot;Console&quot; is one of many. When you type &quot;Console.Write(&quot; you will see &quot;Console.Write(bool value)&quot;. This means that you can give the &quot;Write&quot; method data of the basic data type bool (true or false) and it will write that for you on the screen. The method &quot;Write&quot; has the return data type void and that means that the method won&#39;t return anything. In total there are 18 methods with the name &quot;Write&quot; in the class &quot;Console&quot;, but they all have different parameters. This is called &lt;b&gt;method overloading&lt;/b&gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/overloadingcalculateprice.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;327&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/overloadingcalculateprice.jpg&quot; width=&quot;319&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can for example copy paste your &quot;CalculatePrice&quot; method and give it no parameters, more parameters or different parameters. Don&#39;t forget that your &quot;costs&quot; variable might not exist if you change the parameters. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/calculatepriceexplained.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;349&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/calculatepriceexplained.jpg&quot; width=&quot;475&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Now back to calculating the price. Add the following to your method &quot;CalculatePrice&quot;: &lt;br /&gt;
&lt;blockquote&gt;int price = 0;&lt;br /&gt;
price = costs * 2;&lt;br /&gt;
price = price / 5;&lt;br /&gt;
price = price + 2;&lt;br /&gt;
price = price - 2;&lt;br /&gt;
return price;&lt;/blockquote&gt;&quot;int price = 0;&quot; creates a variable that will hold the price. &quot;price = costs * 2&quot; can be looked at as &quot;10 = 5 * 2&quot; which is the same as &quot;5 * 2 = 10&quot;. You have to memorise that first the &quot;5 * 2&quot; will be calculated with the outcome of &quot;10&quot;. On the next line you&#39;ll see &quot;price = price / 5&quot;. It looks like this before it&#39;s been calculated: &quot;10 = 10 / 5&quot;. After calculating it looks like &quot;2 = 2 / 5&quot;, but that doesn&#39;t matter anymore, because you have your answer, namely &quot;2&quot; and you don&#39;t need anything more from that piece of code. The same happens for the rest: &quot;price = price + 2&quot; -&amp;gt; &quot;4 = 2 + 2&quot; and &quot;price = price - 2&quot; -&amp;gt; &quot;2 = 4 - 2&quot;. In the end the variable &quot;price&quot; has the data &quot;2&quot;, so the method &quot;CalculatePrice&quot; returns the number &quot;2&quot;. The &quot;return&quot; keyword makes your application stop executing your method at that point even if it hasn&#39;t reached the end of your method yet. &lt;br /&gt;
&lt;br /&gt;
Now you have a &quot;CalculatePrice&quot; method that calculates the price based on the costs. Make use of that method by typing the following in the &quot;Main&quot; method above the method &quot;ShowHelloWorld&quot;: &lt;br /&gt;
&lt;blockquote&gt;int computerMouseCosts = 5; &lt;br /&gt;
int computerMousePrice = CalculatePrice(computerMouseCosts); &lt;br /&gt;
Console.Write(computerMousePrice);&lt;/blockquote&gt;&quot;int computerMouseCosts = 5;&quot; is the 5 dollar costs for the computer mouse your manager wants to determine the price on. &quot;int computerMousePrice = CalculatePrice(computerMouseCosts);&quot; is where the &quot;CalculatePrice&quot; method will calculate the price based on the costs of the computer mouse and the price will be returned by the method &quot;CalculatePrice&quot; to the variable &quot;computerMousePrice&quot;. The last step is to write the price on your screen by typing &quot;Console.Write(computerMousePrice);&quot;. Run your application by typing F5 on your keyboard and it should show &quot;2Hello World!&quot;. &lt;br /&gt;
&lt;br /&gt;
You&#39;re a good programmer so you were already going to change &quot;Console.Write(computerMousePrice);&quot; to &quot;Console.Write(computerMousePrice + &quot;\n&quot;);&quot;. Run your application now and you should see &quot;Hello World!&quot; on a new line.&lt;br /&gt;
&lt;br /&gt;
You would&#39;ve saved yourself from copy pasting your code by using the &quot;CalculatePrice&quot; method if your manager wanted to calculate more prices that are calculated the same way. Too bad that your manager got fired for trying to steal the fire alarm, but you got promoted to manager by showing the higher ups what you&#39;ve learned so far.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFNzM0M2IyNGUtOTkzZS00ZGMzLWJkNGQtNDUyNzBiZGZiYTNm&amp;amp;export=download&amp;amp;authkey=CKjztvAG&amp;amp;hl=en&quot;&gt;Source Code Methods Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/03/classes.html&quot;&gt;&amp;gt;&amp;gt; Classes&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/6291001405637215161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/methods.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6291001405637215161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/6291001405637215161'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/methods.html' title='Methods'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-8724111252279775453</id><published>2011-02-21T06:41:00.001-08:00</published><updated>2012-06-21T16:41:10.146-07:00</updated><title type='text'>Variables</title><content type='html'>&lt;b&gt;Variables&lt;/b&gt; are words that can hold data. When you have to show the same &quot;Hello World!&quot; on your screen ten times, then it&#39;s easier to put that data in a word. This saves you from typing &quot;Hello World!&quot; all the time. Sometimes you will make the variable name longer than the text itself, but that doesn&#39;t matter. Visual Studio has a list of all the variables you made and it will give you the option to just type the first few letters and then you can press &quot;Enter&quot; on your keyboard. This will autocomplete your word. It&#39;s like when you type something in Google and it will autocomplete what you&#39;re searching for, that is if what you&#39;re searching for is in Google&#39;s list.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/HelloWorldprojectopened.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/HelloWorldprojectopened.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Let&#39;s start by opening your old &quot;Hello World!&quot; project or make a new one with the exact same code. Replace the text &quot;Hello World!&quot; with a variable.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariables.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariables.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Start with &lt;b&gt;declaring&lt;/b&gt; the variable &quot;helloWorld&quot; by typing &quot;string helloWorld = &quot;Hello World!&quot;;&quot; above &quot;Console.Write(&quot;Hello World!&quot;);&quot; and replace &quot;Console.Write(&quot;Hello World!&quot;);&quot; with &quot;Console.Write(helloWorld);&quot;. If you run your application by pressing F5 on your keyboard now it should show the exact same thing as when you started it the last time.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/datatypesexplained2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;169&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/datatypesexplained2.jpg&quot; width=&quot;368&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;String&lt;/b&gt; is a special &lt;b&gt;data type&lt;/b&gt; in C# namely a &lt;b&gt;basic data type&lt;/b&gt;. String tells your variable with the name &quot;helloWorld&quot; that it will hold multiple letters and/or signs or in our case &quot;Hello World!&quot;. In C# there are in total 15 basic data types and are shown in blue in Visual Studio:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;bool &lt;/b&gt;: true or false&lt;/li&gt;
&lt;li&gt;&lt;b&gt;sbyte&lt;/b&gt;: -128 to 127.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;byte&lt;/b&gt; : 0 to 255&lt;/li&gt;
&lt;li&gt;&lt;b&gt;char&lt;/b&gt; : One letter or sign&lt;/li&gt;
&lt;li&gt;&lt;b&gt;short&lt;/b&gt; : -32,768 to 32,767&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ushort&lt;/b&gt; : 0 to 65,535&lt;/li&gt;
&lt;li&gt;&lt;b&gt;int&lt;/b&gt; : -2,147,483,648 to 2,147,483,647&lt;/li&gt;
&lt;li&gt;&lt;b&gt;uint &lt;/b&gt;; : 0 to 4,294,967,295&lt;/li&gt;
&lt;li&gt;&lt;b&gt;long&lt;/b&gt; : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ulong&lt;/b&gt; : 0 to 18,446,744,073,709,551,615&lt;/li&gt;
&lt;li&gt;&lt;b&gt;decimal&lt;/b&gt; : ±1.0 × 10^−28 to ±7.9 × 10^28 - numbers with comma&lt;/li&gt;
&lt;li&gt;&lt;b&gt;float&lt;/b&gt;; : ±1.5 × 10^−45 to ±3.4 × 10^38 - numbers with a comma&lt;/li&gt;
&lt;li&gt;&lt;b&gt;double&lt;/b&gt; : ±5.0 × 10^−324 to ±1.7 × 10^308 - numbers with comma&lt;/li&gt;
&lt;li&gt;&lt;b&gt;string&lt;/b&gt; : Multiple letters and/or signs&lt;/li&gt;
&lt;li&gt;&lt;b&gt;object&lt;/b&gt; : This can be &lt;b&gt;anything.&lt;/b&gt; It&#39;s data without a meaning.&lt;/li&gt;
&lt;/ul&gt;
You&#39;ll probably think &quot;Why not just always use string?&quot;. That&#39;s because you&#39;ll want to see the difference between data, so you can expect what kind of data it will be. When you will use libraries of the .NET Framework you won&#39;t be able to see the code behind it, but you will know what kind of data it will give you thanks to the basic data types. Memorise that &lt;b&gt;&quot;6&quot;&lt;/b&gt;  is a string (like &quot;Hello World!&quot;) and &lt;b&gt;6&lt;/b&gt; without &quot; signs around it is a number like int, short, long and etc. The same counts for booleans (bool for short): &quot;true&quot; is a string and true without &quot; signs around it is a boolean.&lt;br /&gt;
&lt;br /&gt;
You will probably have to practice a lot in order to memorise all the basic data types and you should, because they&#39;re really important. The most used basic data types are: string, object, int and bool, so you should start with those.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariablesint.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariablesint.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Back to the coding part. You can show numbers on your screen by using int. Replace &quot;string helloWorld = &quot;Hello World!&quot;;&quot; with &quot;int randomNumber = 25;&quot; and replace &quot;Console.Write(helloWorld);&quot; with &quot;Console.Write(randomNumber);&quot;. Run your application and you should see the number &quot;25&quot; on your screen.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariablesbool.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariablesbool.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You can do the same with booleans (bool for short). Replace &quot;int randomNumber = 25;&quot; with &quot;bool randomBoolean = true;&quot; and replace &quot;Console.Write(randomNumber);&quot; with &quot;Console.Write(randomBoolean);&quot;. Run your application and you should see &quot;True&quot; on your screen.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariablesrandom3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/helloworldvariablesrandom3.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Until now you&#39;ve only used variables with basic data types, but there are also normal data types which you can add yourself or are available in the .NET Framework. Replace &quot;bool randomBoolean = true;&quot; with &quot;Random myRandomVariable = new Random();&quot; and replace &quot;Console.Write(randomBoolean);&quot; with &quot;Console.Write(myRandomVariable.Next());&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/returndatarandom2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;217&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/returndatarandom2.jpg&quot; width=&quot;459&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Random&lt;/b&gt; is a class in the .NET Framework. &quot;new Random()&quot; returns data with the data type Random (convenient huh?). Your &quot;myRandomVariable&quot; variable now has the information to call the &quot;Next&quot; method of the &quot;Random&quot; class. The &quot;Next&quot; method returns a random number with the basic data type int (point with your cursor on &quot;Next&quot;). You should see a random number on your screen when you start your application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note&lt;/b&gt;: You should not take it easy on naming your variables. You should give variables a correct description based on the data it will hold in order for you and others to easily understand your (large) projects.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFMzRjMTg0MjQtNWRiZi00ZDMzLWI4NDEtMzljNzNkZjMzMjYy&amp;amp;export=download&amp;amp;authkey=CO3Y-dQF&amp;amp;hl=en&quot;&gt;Source Code Variables Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/basic-calculations.html&quot;&gt;&amp;gt;&amp;gt; Basic Calculations&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/8724111252279775453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/variables.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8724111252279775453'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8724111252279775453'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/variables.html' title='Variables'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-7348403156056184663</id><published>2011-02-20T10:35:00.000-08:00</published><updated>2011-08-29T10:39:03.302-07:00</updated><title type='text'>Visual Studio Templates</title><content type='html'>This page will discuss the templates Visual Studio has in order for you to live a lazy programmer life.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/NewProject.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; width=&quot;480&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/NewProject.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
First you will have to start Visual Studio -&gt; click File (upper left corner) -&gt; click New Project. You will see six different &lt;b&gt;templates&lt;/b&gt;: Windows Forms Application, Console Application, WPF Application, Class Library, WPF Browser Application and Empty Project. A template in Visual Studio is a pre-programmed application which you can work further on. It saves the trouble from starting with nothing when creating a new project while you want to start at a certain point anyways.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ConsoleApplication.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; width=&quot;480&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ConsoleApplication.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Console Applications&lt;/b&gt; don&#39;t look flashy at all. They&#39;re easy to learn C# with, because you don&#39;t get distracted by anything shiny. It&#39;s just text and that&#39;s what you need to get a slow and easy start. This template is going to be used for all the basic tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/C_sharp_drawing_text.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;245&quot; width=&quot;320&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/C_sharp_drawing_text.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Windows Forms Applications&lt;/b&gt; are applications that you see a lot in Windows, like Notepad, Calculator and such. Visual Studio made it so that you can drag programmable buttons, dropdown boxes and many more on your own Windows Form Application. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/dynamicButtons.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;245&quot; width=&quot;320&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/dynamicButtons.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;WPF Applications&lt;/b&gt; are like Windows Forms Applications, but WPF makes it easier to make your application look flashy and it uses a language called Extensible Application Markup Language (XAML) to initialize structured values and objects.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/DLL.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;227&quot; width=&quot;193&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/DLL.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Class Libraries&lt;/b&gt; are for creating .DLL files. Class Libraries aren&#39;t for creating anything visual. They&#39;re used for writing code that can be used for many other applications. When you write code for using a database you will probably want to use that same code for other applications that you will write in the near future. In Visual Studio you can make a &lt;b&gt;reference&lt;/b&gt; to these .DLL files, so you can make quick use of them. Some of the .DLL files on your computer can also be used as a reference, but most of them will give an error when trying to use them. For example you can use parts of the Microsoft Office Word application in your own application by making a reference to the right .DLL.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;WPF Browser Applications&lt;/b&gt; are used for Rich Internet Applications. Rich Internet Applications are basically web pages that you open on your browser that look a lot like the applications you open on your computer.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Empty Projects&lt;/b&gt; are for hardcore people that want to write everything from scratch. So are you hardcore, then look no further and open your empty project and dive in!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/hello-world.html&quot;&gt;&gt;&gt; Hello World!&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/7348403156056184663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/visual-studio-templates.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/7348403156056184663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/7348403156056184663'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/visual-studio-templates.html' title='Visual Studio Templates'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-8909082156523219226</id><published>2011-02-19T17:43:00.000-08:00</published><updated>2012-06-21T16:53:21.377-07:00</updated><title type='text'>How To Get Started</title><content type='html'>This is the famous &quot;How To Get Started&quot; page. This page will show what application will be used and the project type that will be used for the basic tutorials.&lt;br /&gt;
&lt;br /&gt;
The easiest application to code C# in must be Visual Studio. Visual Studio uses a framework called the &lt;b&gt;.NET Framework&lt;/b&gt;. The .NET Framework is basically a library full of books that you can use. When you program you basically write a book, but sometimes you need help from other books to write your own because you don&#39;t know certain things. Of course you can always write your own, but it is way quicker and easier to use a book than to write one all by yourself. There are more frameworks that you can download and use, but the .NET Framework is the only one you will need for the basics.&lt;br /&gt;
&lt;br /&gt;
There are several versions of Visual Studio: Express, Professional, Premium, Ultimate and Test Professional. The &lt;b&gt;Express&lt;/b&gt; version is free and is divided in five different editions: C#, Visual Basic, C++, Web Developer and Windows Phone. We will be using the C# version: &lt;b&gt;Visual C# Express&lt;/b&gt;. It can be found here: &lt;a href=&quot;http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-csharp-express&quot;&gt;http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-csharp-express&lt;/a&gt;. You can always get one of the other Visual Studio versions in ways I&#39;d rather not know.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/how-to-download-csharp-express2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/how-to-download-csharp-express2.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
After selecting your language in the dropdown box the download will begin shortly. The file will be small, because that file will only start the actual download of Visual C# Express. Start &quot;vcs_web.exe&quot; (the file you just downloaded) and it will show something that is loading. Go through the setup after it has been loaded. Press &quot;Next&quot;, accept the License Terms and press &quot;Next&quot; and then press &quot;Install&quot;. It will start downloading the entire application before installing it. After that just press &quot;Exit&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/csharp-express.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/csharp-express.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Start Microsoft Visual C# 2010 Express by going to: Start -&amp;gt; All Programs -&amp;gt; Microsoft Visual Studio 2010 Express -&amp;gt; Microsoft Visual C# 2010 Express.&lt;br /&gt;
&lt;br /&gt;
Congratulations, you have installed Visual Studio C# 2010 Express successfully! Don&#39;t go crazy and program something brilliant just yet or I won&#39;t be able to take the credit. Keep following the tutorials instead.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/visual-studio-templates.html&quot;&gt;&amp;gt;&amp;gt; Visual Studio Templates&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/8909082156523219226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/how-to-get-started.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8909082156523219226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/8909082156523219226'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/how-to-get-started.html' title='How To Get Started'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6985766342586546951.post-3634906314798753022</id><published>2011-02-19T11:40:00.000-08:00</published><updated>2012-06-21T16:48:45.037-07:00</updated><title type='text'>Hello World!</title><content type='html'>The first thing you do when learning a new programming language is showing &quot;Hello World!&quot; on your screen by using the programming language that you&#39;re trying to learn. The reason we do this is because it&#39;s the simplest way to show something on the screen and to give you that extra motivation to keep going. The second reason is that it&#39;s a tradition after it was first introduced in the book &quot;The C Programming Language&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/new-project-helloworld.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/new-project-helloworld.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
First you have to start Visual Studio -&amp;gt; click File (upper left corner) -&amp;gt; click New Project -&amp;gt; click Console Application -&amp;gt; Fill in &quot;HelloWorld&quot; for the project name -&amp;gt; click OK.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/HelloWorld-Explained.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/HelloWorld-Explained.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Don&#39;t freak out, you don&#39;t have to understand everything all at once, except the three parts that are circled by red. &lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;Debug&lt;/b&gt; button (&lt;b&gt;1&lt;/b&gt;) is where you click on to test your application. You basically just start the application within Visual Studio and check if your application has errors which will be shown in Visual Studio. If you click on it now you will see something opening and closing.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;Text Editor&lt;/b&gt; (&lt;b&gt;2&lt;/b&gt;) is where you type your code. Your application starts in &quot;&lt;b&gt;static void Main(string[] args){ }&lt;/b&gt;&quot; which is called a &lt;b&gt;method&lt;/b&gt;. It&#39;s a written rule that your application will start in the method called &quot;Main&quot;. Your first code will be written in-between the { } signs of that method.&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;Solution Explorer&lt;/b&gt; (&lt;b&gt;3&lt;/b&gt;) is a list of all the files that exist in your project and the made references to libraries that you are using in your project. You&#39;re going to write the code in a text file called &quot;Program.cs&quot; and the contents of that text file is shown in the Text Editor.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/console-write-read2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/console-write-read2.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Let&#39;s get started. Type &quot;&lt;b&gt;Console.Write(&quot;Hello World!&quot;);&lt;/b&gt;&quot; and on the next line type &quot;&lt;b&gt;Console.Read();&lt;/b&gt;&quot;. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classesmethodsexplained.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;217&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/classesmethodsexplained.jpg&quot; width=&quot;459&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&quot;Console&quot; is a &lt;b&gt;class&lt;/b&gt; like &quot;Program&quot; is a class in your application right now. &quot;Write&quot; is the &lt;b&gt;method&lt;/b&gt; that is in the class &quot;Console&quot; like &quot;Main&quot; is a method in the class &quot;Program&quot; of your application right now and both the classes and the class their methods are seperated by a dot. The only difference is that you won&#39;t be able to see what is inside the class &quot;Console&quot; (except a list of the method names it has) or the method &quot;Write&quot;, because they&#39;re protected by the .NET Framework. &quot;Hello World&quot; is the &lt;b&gt;parameter &lt;/b&gt;that you&#39;re giving to the method &quot;Write&quot;. Basically you can type &quot;Program.Main(null);&quot; like you just did with &quot;Console.Write(&quot;Hello World!&quot;);&quot; (null means that you&#39;re giving it no data). Putting &quot;Program.Main(null);&quot; in your code is not a good idea though, because that will start your application an infinite times, which will destroy the world. &lt;br /&gt;
&lt;br /&gt;
&quot;Console.Write(&quot;Hello World!&quot;);&quot; will write &quot;Hello World!&quot; on the console. &quot;Console.Read();&quot; will make the application wait until you press the &quot;Enter&quot; key on your keyboard. The application will close right away if you don&#39;t type &quot;Console.Read();&quot;, because when a console application reaches the end of its &quot;Main&quot; method, the application closes.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ConsoleApplication.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;331&quot; src=&quot;http://i1238.photobucket.com/albums/ff489/cplusplusplusplustutorials/ConsoleApplication.jpg&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now click on the Debug button or press F5 on your keyboard to start your application. Your application will be read from top to bottom, so don&#39;t think every line of code will be executed at the same time. If your code is exactly like on the previous picture, then there should be no problems and the application should run perfectly. You might&#39;ve forgotten a ; sign, so make sure you didn&#39;t. If everything went perfectly, then congratulations on your first C# console application! Save your project by pressing &quot;Control + Shift + S&quot; on your keyboard, unless you don&#39;t need to with your Visual Studio, because Visual Studio saved your project when you created it unlike my Visual Studio.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/uc?id=0B8J53hObDGsFYmJlOGNlMDYtMTI5MS00NGJlLWFlMWItNjBiMjg2M2NiODNl&amp;amp;export=download&amp;amp;authkey=CN2sx34&amp;amp;hl=en&quot;&gt;Source Code HelloWorld Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://cplusplusplusplus.blogspot.com/2011/02/variables.html&quot;&gt;&amp;gt;&amp;gt; Variables&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusplusplus.blogspot.com/feeds/3634906314798753022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/hello-world.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/3634906314798753022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6985766342586546951/posts/default/3634906314798753022'/><link rel='alternate' type='text/html' href='http://cplusplusplusplus.blogspot.com/2011/02/hello-world.html' title='Hello World!'/><author><name>Marc</name><uri>http://www.blogger.com/profile/14142168119690447411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='25' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIGS1jbNVzS6VhTBegORtH8npdI1VasS3JRULipz-mWbOm5MhQFRe1RfnYMx9Aw7tJf3sIUA61KYZI1f0qudLSDw7_VHHMMjY7aXaq2Fv_DINA3XrB9gx_5_kqMW_Xw/s220/2006.20_1b.jpg'/></author><thr:total>1</thr:total></entry></feed>