You are on page 1of 10

Table of Contents

Part I Getting Started........................................................................................................................................3 Introduction.................................................................................................................................................3 Software You'll Need..................................................................................................................................4 Formatting Standards Used in this oo!....................................................................................................." #hat's Ne$t%................................................................................................................................................&

Part I Getting Started


Introduction
Are We Allowed To Have Fun Here ?

I sus'ect I !now what (ou)re thin!ing * +I want to write a 'rogram and I want to write it now, -oding is the cool 'art. I don)t want to read half the /oo! /efore I can write m( first 'rogram. In fact0 this sentence is getting too long alread( 1 I want to get going,2

3ruthfull(0 I)4e (et to meet a 'rogrammer who can resist di4ing in after all0 if (ou /ought a new /i!e0 would (ou sit down and read the /oo! first% 5uite li!el( not (ou)d lea' a/oard0 ta!e it for a s'in0 fall on (our face and onl( later disco4er the fact that the /ra!es on this model are o''osite to the usual con4entions. So let)s ma!e a deal. #e)ll di4e right in within this first cha'ter. 6nce (ou)4e installed the software0 (ou can run some of the sam'le 'rograms and0 if (ou're feeling /ra4e0 'erha's e4en tr( modif(ing them. ut the code will loo! strange and won)t ma!e much sense (ou)ll /e riding /lind and when (ou ma!e a small mista!e (ou)ll /e clueless as to what)s wrong and how to fi$ it. It 7ust won)t wor! and (ou won)t !now wh(. 3hat)s when (ou !now it)s time to start stud(ing the theor( li!e a 'ro. 8on't /ecome discouraged when something doesn't wor!0 and gi4e u'. #hen that time comes0 read the rest of the /oo!. o!a(%

The Really Important Part

In 'rogramming0 as in all other 'rofessions0 the 'eo'le who achie4e the most are those who lo4e what the( do. If (ou en7o( (our 'rogramming0 (ou)ll find it hard to sto' (ourself learning new things. Your need to !now will dri4e (ou forward and stud(ing further will 7ust /e something that ha''ens along the wa(.

So0 a/o4e all0 enjoy yourself as (ou master the world of -9 'rogramming,

Software ou!ll "eed


3o de4elo' -9 'rograms0 (ou)ll need : ;. 3he <icrosoft .N=3 Framewor! >.?0 which is a4aila/le0 free0 from htt':@@msdn.microsoft.com@netframewor!@downloads@u'dates@. >. A .N=3 de4elo'ment en4ironment. #e recommend <icrosoft Bisual -9 >??C =$'ress =dition0 which is a4aila/le free from <icrosoft at htt':@@msdn.microsoft.com@4studio@e$'ress@4isualcshar'@ . 3he Bisual -9 >??C =$'ress installation 'ac!age includes the .N=3 Framewor! so (ou don)t need to worr( a/out installing item 9; a/o4e se'aratel(. 3. Dastl(0 (ou need to co'( the /oo!'s e$am'le files to a dri4e on (our own com'uter. =$tract the file e$am'le.Ei' to an( folder of (our choosing. Fust remem/er which location (ou choose since (ou)ll /e as!ed to o'en the files from there later.
#ore A$out #icrosoft %isual &' ())* +,press +dition

It is 'ossi/le to create -9 'rograms using nothing /ut a sim'le te$t editor Gli!e Note'adH and something called the 2-9 com'iler2 included with the .N=3 Framewor!. 3o ma!e things a little easier though0 and to ma!e sure (ou can carr( on further once (ou'4e read this /oo!0 we suggest (ou use a de4elo'ment en4ironment such as Bisual -9 =$'ress. It is a lightweight en4ironment for de4elo'ing #indows a''lications and console Gcommand1lineH a''lications0 using -9. It's im'ortant that (ou understand that this $oo- is not a$out teachin. you a$out the %isual &' +,press +dition software product / rather it teaches you a$out the &' lan.ua.e. Bisual -9 =$'ress also has lots of snaEE( features li!e writing -9 code for (ou when (ou drag1and1dro' a /utton or other control onto the

'age. 3hat's cool and (ou're welcome to use it 1 /ut this /oo! aims to teach (ou -9 2from the ground u'2. #e'd li!e (ou to learn to write -9 code /( hand first 1 so that (ou reall( understand what's ha''ening. If (ou want to learn more a/out the Bisual -9 =$'ress de4elo'ment en4ironment0 go to the we/site at htt':@@msdn.microsoft.com@4studio@e$'ress@4isualcshar'@.
Writin. a "ew Pro.ram 0sin. %isual &' +,press

3o start Bisual -9 =$'ress0 clic! S3AI3 1J All Programs 1J <icrosoft Bisual -9 >??C =$'ress =dition 3o start a new 'ro7ect0 sim'l( select File 1J New Pro7ect and then choose a 'ro7ect t('e. #e will start with some -onsole a''lications and will later mo4e on to #indows a''lications.

For e$am'le0 tr( creating a new -onsole A''lication and clic!ing 6K. #hen the coding window for Pro.ram1cs a''ears0 delete all the code that is automaticall( inserted and t('e a sim'le 'rogram such as this. You can co'( and 'aste it if (ou're feeling lazy. 6r is that smart%,
using System; class PleaseSayYo { static void Main() { Console.WriteLine("Yo!"); Console.ReadLine(); }

<a!e sure (ou t('e it =LA-3DY as a/o4e Ge$ce't that formatting li!e italics can /e ignoredH.

3hen clic! the Iun or Pla( /utton Gor 'ress FCH

If the 'rogram runs successfull(0 it will a''ear after a few moments0 in a window a/o4e the -9 =$'ress window.

#hen (ou're done0 (ou must sto' the 'rogram. Usuall(0 (ou will do this /( clic!ing the L in the to' right1hand corner to close the window.

If there is some 'ro/lem in the code of the 'rogram0 (ou'll /e alerted to this fact. For e$am'le0 (ou notice that in the -9 com'uter language0 we must end e4er( sentence or statement with a semicolon. If (ou tr( deleting the last semicolon 2.2 and then clic!ing the start /utton0 (ou'll see the error message /elow.

In most cases0 (ou will clic! 2No20 and will /e shown some details in the 2=rror Dist2 window0 including an indication of which line num/er the error was found on. If (ou then dou/le1clic! that error descri'tion0 (ou will /e ta!en to the line where the 'ro/lem e$ists0 so that (ou can tr( to correct it.

Runnin. the 2oo-!s Sample Pro.rams

Se4eral of this /oo!'s e$am'le 'rograms need accom'an(ing files. 3hose 'rograms won't run correctl( if (ou sim'l( 'aste the code in as a/o4e. So once (ou'4e co'ied the e$am'le files to some folder on (our com'uter0 (ou should run them /(:

In Bisual -9 =$'ress0 select File 1J 6'en Pro7ect rowse to the folder where (ou sa4ed (our e$am'le files0 and select the 'ro7ect (ou want0 which will alwa(s ha4e a 1csproj Gc9 'ro7ectH e$tension.

-lic! the green Iun /utton.

Formattin. Standards 0sed in this 2ooIn order to ma!e it easier to follow the code sam'les in the /oo!0 we ha4e generall( stuc! to certain ha/its: -onsider this /loc! of code as an e$am'le:
// Main method static void Main() { !!lication.Run( ne" MyButtonClass() ); } // Event handler method void MyButtonClickEventHandler( object sender, EventArgs e ) { mrButton.Text = "You clicked me!"; }

-ode sam'les are written using a slightl( different font to the rest of the te$t GCourier #e"H An( words or s(m/ols that we +choose oursel4esM are written in italics. =$am'les a/o4e include +MyButtonClassM and +mrButtonM. An( words or s(m/ols that are 'art of the -9 language or /uilt into the .N=3 Framewor!0 such as +static 4oid <ainGHM or +.3e$tM0 we write with normal st(le. 2old te$t sim'l( indicates something we want to draw (our attention to. 3wo forward slashes 33 indicate comments to e$'lain the code Gactuall( this is a feature of the -9 languageH. An(thing on the line /e(ond them is ignored /( the com'uter. An e$am'le a/o4e is +@@ <ain methodM.

Part II of the /oo! contains most of the general conce'ts and we often summariEe the !e( conce'ts there. 3hese summaries are called + uilding loc!sM. Nere s a 'artial e$am'le showing how a uilding loc! a''ears. uilding loc! : -lasses All -9 'rograms are /uilt inside classes. 3he /asic structure of a class is written down for the com'uter as follows :
class Animal { }

What!s "e,t?
You will 'ro/a/l( want to 'la( with Bisual -9 =$'ress for a while 1 (ou ma( wish to e$'lore its hel' files and see what it's all a/out. If (ou're new to -90 though0 (ou'll 'ro/a/l( soon find that ha4ing a 'rogramming tool is not enough 1 (ou need more than 7ust a tool in order to communicate with the com'uter.

3hen it's time to tac!le the ne$t 'art of the /oo! 1 learning how to communicate with the com'uter using the -9 'rogramming language.

A$out the 2oo<icrosoft)s newest 'rogramming language0 -90 G'ronounced +c1shar'MH is /oth 'owerful and eas( to use. It 'resents a great o''ortunit( for the new generation of de4elo'ers to start out with a language that is highl( res'ected in the modern wor!'lace. 3his te$t introduces o/7ect1oriented 'rogramming to the (oung de4elo'er Gcore target age is ;>1;OH in a lightweight fashion0 allowing them to get started with real 'rograms in a #indows en4ironment. A$out the Author <artin 8re(er is an e$1high school teacher who now heads a team of software de4elo'ers in South Africa. Nis formal Pualifications are a Nigher 8i'loma in =ducation : Ph(sical Science and a achelor of Science 8egree : -om'uter Science and Information S(stems.

You might also like