You are on page 1of 48

1e|emark Un|vers|ty Co||ege

ueparLmenL of LlecLrlcal Lnglneerlng, lnformaLlon 1echnology and CyberneLlcs


Faculty of Technology, Postboks 203, Kjlnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01


lnLroducLlon Lo vlsual
SLudlo and C#
PAnS-L11L8 PALvC8SLn, 2014.03.12


2


1able of ConLenLs
1. lnLroducLlon ....................................................................................................................... 3
1.1. vlsual SLudlo ............................................................................................................... 3
1.2. C# ................................................................................................................................ 6
1.3. .nL1 lramework .......................................................................................................... 6
1.4. Cb[ecL-CrlenLed rogrammlng (CC) ......................................................................... 7
2. vlsual SLudlo ...................................................................................................................... 8
2.1. lnLroducLlon ................................................................................................................ 8
2.2. CeLLlng SLarLed ........................................................................................................... 8
2.2.1. lnLegraLed uevelopmenL LnvlronmenL (luL) ....................................................... 8
2.2.2. new ro[ecL .......................................................................................................... 9
2.2.3. SoluLlon Lxplorer ................................................................................................ 10
2.2.4. 1oolbox .............................................................................................................. 11
2.2.3. LdlLors and ueslgners ........................................................................................ 12
2.2.6. roperLles wlndow ............................................................................................. 12
2.2.7. 8ulld and uebug 1ools ....................................................................................... 13
3. Wlndows rogrammlng ................................................................................................... 13
3.1. lnLroducLlon .............................................................................................................. 13
3.1.1. Wlndows lorms ................................................................................................. 13
3.1.2. Wl .................................................................................................................... 16
3.2. Pello World ............................................................................................................... 16
4. CeLLlng SLarLed wlLh C# ................................................................................................... 19
3 1able of ConLenLs
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
4.1. lnLroducLlon .............................................................................................................. 19
4.2. uaLa 1ypes and varlables .......................................................................................... 19
4.2.1. 8oolean Lype ...................................................................................................... 20
4.2.2. numerlc Lypes: lnLegrals, lloaLlng olnL, ueclmal ............................................. 20
4.2.3. SLrlng Lype .......................................................................................................... 20
4.2.4. Arrays ................................................................................................................. 21
4.3. ConLrol llow .............................................................................................................. 21
4.3.1. 1he lf SLaLemenL ................................................................................................ 21
4.3.2. 1he swlLch SLaLemenL ........................................................................................ 22
4.4. Loops ......................................................................................................................... 23
4.4.1. 1he whlle Loop ................................................................................................... 23
4.4.2. 1he do Loop ....................................................................................................... 23
4.4.3. 1he for Loop ....................................................................................................... 24
4.4.4. 1he foreach Loop ............................................................................................... 24
4.3. MeLhods .................................................................................................................... 24
4.3.1. nonsLaLlc MeLhods ............................................................................................ 23
4.3.2. SLaLlc MeLhods ................................................................................................... 23
4.6. namespaces .............................................................................................................. 26
4.7. Classes ....................................................................................................................... 26
4.7.1. ConsLrucLor ........................................................................................................ 27
4.8. roperLles ................................................................................................................. 29
4.9. namlng ConvenLlon .................................................................................................. 31
3. More Cb[ecL-orlenLed 1echnlques ................................................................................... 33
3.1. lnherlLance ................................................................................................................ 33
3.2. olymorphlsm ........................................................................................................... 34
3.3. LncapsulaLlon ............................................................................................................ 33
4 1able of ConLenLs
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
6. LxcepLlon Pandllng .......................................................................................................... 36
7. Wlndows lorms Lxample ................................................................................................. 38
8. Web rogrammlng ........................................................................................................... 44
8.1. lnLroducLlon .............................................................................................................. 44
8.2. P1ML ......................................................................................................................... 44
8.3. Web 8rowser ............................................................................................................ 44
8.4. CSS ............................................................................................................................ 43
8.3. !avaScrlpL .................................................................................................................. 43
8.6. AS.nL1 ..................................................................................................................... 43
8.7. A!Ax/ AS.nL1 A!Ax ................................................................................................. 46
8.8. SllverllghL .................................................................................................................. 46
9. uaLabase rogrammlng ................................................................................................... 47
9.1. AuC.nL1 ................................................................................................................... 47


3

1. lnLroducLlon
ln Lhls 1uLorlal we wlll use vlsual SLudlo and C#. C# ls Lhe programmlng language, whlle
vlsual SLudlo ls Lhe developmenL envlronmenL.
useful llnks:
vlsual SLudlo: http:]]msdn.m|crosoft.com]en-us]||brary]dd8318S3.aspx
C#: http:]]msdn.m|crosoft.com]en-us]||brary]kx37x362.aspx
1.1. vlsual SLudlo
MlcrosofL vlsual SLudlo ls an lnLegraLed developmenL envlronmenL (luL) from MlcrosofL. lL
can be used Lo develop console and graphlcal user lnLerface appllcaLlons along wlLh
Wlndows lorms appllcaLlons, web slLes, web appllcaLlons, and web servlces ln boLh naLlve
code LogeLher wlLh managed code for all plaLforms supporLed by MlcrosofL Wlndows,
Wlndows hone, Wlndows CL, .nL1 lramework, .nL1 CompacL lramework and MlcrosofL
SllverllghL.
8elow we see Lhe lnLegraLed developmenL envlronmenL (luL) ln vlsual SLudlo:

6 lnLroducLlon
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
new pro[ecLs are creaLed from Lhe new ro[ecL" wlndow:

1.2. C#
C# ls pronounced see sharp". C# ls an ob[ecL-orlenLed programmlng language and parL of
Lhe .nL1 famlly from MlcrosofL. C# ls very slmllar Lo C++ and !ava. C# ls developed by
MlcrosofL and works only on Lhe Wlndows plaLform.
1.3. .nL1 lramework
1he .nL1 lramework (pronounced doL neL") ls a sofLware framework LhaL runs prlmarlly on
MlcrosofL Wlndows. lL lncludes a large llbrary and supporLs several programmlng languages
whlch allow language lnLeroperablllLy (each language can use code wrlLLen ln oLher
languages). 1he .nL1 llbrary ls avallable Lo all Lhe programmlng languages LhaL .nL1
supporLs. rograms wrlLLen for Lhe .nL1 lramework execuLe ln a sofLware envlronmenL,
known as Lhe Common Language 8unLlme (CL8), an appllcaLlon vlrLual machlne LhaL
provldes lmporLanL servlces such as securlLy, memory managemenL, and excepLlon handllng.
1he class llbrary and Lhe CL8 LogeLher consLlLuLe Lhe .nL1 lramework.
7 lnLroducLlon
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
1.4. Cb[ecL-CrlenLed rogrammlng (CC)
Cb[ecL-orlenLed programmlng (CC) ls a programmlng language model organlzed around
"ob[ecLs" raLher Lhan "acLlons" and daLa raLher Lhan loglc. PlsLorlcally, a program has been
vlewed as a loglcal procedure LhaL Lakes lnpuL daLa, processes lL, and produces ouLpuL daLa.
1he flrsL sLep ln CC ls Lo ldenLlfy all Lhe ob[ecLs you wanL Lo manlpulaLe and how Lhey
relaLe Lo each oLher, an exerclse ofLen known as daLa modellng. Cnce you've ldenLlfled an
ob[ecL, you generallze lL as a class of ob[ecLs and deflne Lhe klnd of daLa lL conLalns and any
loglc sequences LhaL can manlpulaLe lL. Lach dlsLlncL loglc sequence ls known as a meLhod. A
real lnsLance of a class ls called an ob[ecL" or an lnsLance of a class". 1he ob[ecL or class
lnsLance ls whaL you run ln Lhe compuLer. lLs meLhods provlde compuLer lnsLrucLlons and
Lhe class ob[ecL characLerlsLlcs provlde relevanL daLa. ?ou communlcaLe wlLh ob[ecLs - and
Lhey communlcaLe wlLh each oLher.
lmporLanL feaLures wlLh CC are:
Classes and Cb[ecLs
lnherlLance
olymorphlsm
LncapsulaLlon
S|mu|a was Lhe flrsL ob[ecL-orlenLed programmlng language. Slmula was developed ln Lhe
1960s by krlsLen nygaard from norway.
!ava, yLhon, C++, vlsual 8aslc .nL1 and C# are popular CC languages Loday.
Slnce Slmula-Lype ob[ecLs are relmplemenLed ln C++, !ava and C# Lhe lnfluence of Slmula ls
ofLen undersLaLed. 1he creaLor of C++ (1979), 8[arne SLrousLrup (from uenmark), has
acknowledged LhaL Slmula was Lhe greaLesL lnfluence on hlm Lo develop C++.

8

2. vlsual SLudlo
2.1. lnLroducLlon
Pome page of vlsual SLudlo: http:]]www.m|crosoft.com]v|sua|stud|o
1here exlsL dlfferenL verslons of vlsual SLudlo, such as vlsual SLudlo Lxpress (free), vlsual
SLudlo rofesslonal, vlsual SLudlo remlum and vlsual SLudlo ulLlmaLe.
2.2. CeLLlng SLarLed
2.2.1. lnLegraLed uevelopmenL LnvlronmenL (luL)
1he vlsual SLudlo producL famlly shares a slngle lnLegraLed developmenL envlronmenL (luL)
LhaL ls composed of several elemenLs: Lhe Menu bar, SLandard Loolbar, varlous Lool wlndows
docked or auLo-hldden on Lhe lefL, boLLom, and rlghL sldes, as well as Lhe edlLor space. 1he
Lool wlndows, menus, and Loolbars avallable depend on Lhe Lype of pro[ecL or flle you are
worklng ln.
8elow we see Lhe vlsual SLudlo luL (lnLegraLed uevelopmenL LnvlronmenL):

9 vlsual SLudlo
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
2.2.2. new ro[ecL
1he flrsL Lhlng you do when you wanL Lo creaLe a new appllcaLlon ls Lo creaLe a new pro[ecL.
1hls can be done from Lhe SLarL age:

Cr from Lhe llle menu:

1hen Lhe new ro[ecL" wlndow appears:
10 vlsual SLudlo
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

ln Lhls wlndow you wlll selecL an approprlaLe LemplaLe based on whaL klnd of appllcaLlon you
wanL Lo creaLe, and a name and locaLlon for your pro[ecL and soluLlon.
1he mosL common appllcaLlons are:
Wlndows lorm AppllcaLlon
Console AppllcaLlon
Wl AppllcaLlon
AS.nL1 Web AppllcaLlon
SllverllghL AppllcaLlon
2.2.3. SoluLlon Lxplorer
SoluLlons and pro[ecLs conLaln lLems LhaL represenL Lhe references, daLa connecLlons,
folders, and flles LhaL you need Lo creaLe your appllcaLlon. A soluLlon conLalner can conLaln
mulLlple pro[ecLs and a pro[ecL conLalner Lyplcally conLalns mulLlple lLems.
11 vlsual SLudlo
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

2.2.4. 1oolbox
1he 1oolbox conLalns all Lhe necessary conLrols, eLc. you need Lo creaLe your user lnLerface.
See llgure below.

1he 1oolbox conLalns all Lhe conLrols, eLc. we can use ln
our user lnLerface.
ln order Lo use Lhem ln our user lnLerface, we [usL drag
and drop Lhem Lo Lhe lorm", as shown below:

12 vlsual SLudlo
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
2.2.3. LdlLors and ueslgners
vlsual SLudlo has dlfferenL edlLors and deslgn Lools.
Craphlcal user lnLerface ueslgner:

Code LdlLor:

2.2.6. roperLles wlndow
Lach conLrol we have on our user lnLerface has loLs of roperLles we can seL.
13 vlsual SLudlo
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
1hls ls done ln Lhe roperLles wlndow:

2.2.7. 8ulld and uebug 1ools
ln vlsual SLudlo we have loLs of 8ulld and uebugglng 1ools.
8u||d menu:
8elow we see Lhe 8u||d menu:

1he mosL used Lool ls 8u||d So|ut|on" (ShorLcuL key: l6).
Debug menu:
8elow we see Lhe Debug menu:

14 vlsual SLudlo
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

1he mosL used Lool ls Start Debugg|ng" (ShorLcuL key: l3).

13

3. Wlndows rogrammlng
3.1. lnLroducLlon
When creaLlng ordlnary Wlndows appllcaLlons, we can selecL beLween Lhe followlng:
Wlndows lorms AppllcaLlon
Wl AppllcaLlons (Wlndows resenLaLlon loundaLlon)
Wlndows lorms ls Lhe sLandard way of creaLlng Wlndows appllcaLlons and has exlsLed ln
many years, even before .nL1 1.0 (2002) was lnLroduced. Wl ls a new approach from
creaLlng Wlndows appllcaLlons and was lnLroduced wlLh .nL1 lramework 3.0 (2006).
lor example has Lhe vlsual SLudlo luL been enLlrely rewrlLLen uslng Wl.
Wlndows lorms AppllcaLlon and Wl AppllcaLlons wlll be explalned ln more deLall below.
3.1.1. Wlndows lorms
Wlndows lorms ls Lhe sLandard way of creaLlng Wlndows appllcaLlons.
SelecL Wlndows lorms AppllcaLlon" ln Lhe new ro[ecL" wlndow:

16 Wlndows rogrammlng
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
3.1.2. Wl
ueveloped by MlcrosofL, Lhe Wlndows resenLaLlon loundaLlon (or Wl) ls a
compuLer-sofLware graphlcal subsysLem for renderlng user lnLerfaces ln Wlndows-based
appllcaLlons.
Wl ls lnLended Lo Lake over for Lhe LradlLlonal Wlndows lorms.
1he graphlcal user lnLerface ln Wl ls deslgned uslng kAML (LxLenslble AppllcaLlon Markup
Language).
kAML:
lollowlng Lhe success of markup languages for web developmenL, Wl lnLroduces a new
language known as exLenslble AppllcaLlon Markup Language (xAML), whlch ls based on xML.
xAML ls deslgned as a more efflclenL meLhod of developlng appllcaLlon user lnLerfaces
SelecL Wl AppllcaLlon" ln Lhe new ro[ecL" wlndow:

3.2. Pello World
We sLarL by creaLlng a LradlLlonal Pello World" appllcaLlon uslng Wlndows lorms. 1he
appllcaLlon ls shown below:
17 Wlndows rogrammlng
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

1he vlsual SLudlo luL looks llke Lhls:

ln Lhls pro[ecL we use a slmple 1exL8ox (LexL8ox1) and when we sLarL Lhe program Lhe LexL
Pello World" ls wrlLLen Lo Lhe 1exL8ox.
1he code ls as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


18 Wlndows rogrammlng
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
private void Form1_Load(object sender, EventArgs e)
{

textBox1.Text = "Hello World";

}

}
}




19

4. CeLLlng SLarLed wlLh C#
C# ls a modern Cb[ecL-orlenLed programmlng language.
Cb[ecL-orlenLed programmlng (CC) ls a programmlng paradlgm uslng "ob[ecLs" - daLa
sLrucLures conslsLlng of daLa flelds and meLhods LogeLher wlLh Lhelr lnLeracLlons - Lo deslgn
appllcaLlons and compuLer programs. rogrammlng Lechnlques may lnclude feaLures such as
daLa absLracLlon, encapsulaLlon, messaglng, modularlLy, polymorphlsm, and lnherlLance.
4.1. lnLroducLlon
ln Lhls chapLer we wlll sLarL wlLh Lhe baslc all programmlng languages have:.
uaLa 1ypes and varlables
ConLrol llow: lf-Llse, eLc.
Loops: Whlle Loops, lor Loops, eLc.
lurLher we wlll lnLroduce Lhe followlng:
namespaces
Classes
uaLa llelds
MeLhods
roperLles
ln Lhe nexL chapLer we wlll go more ln depLh of whaL Cb[ecL-orlenLed programmlng ls and
lnLroduce Lhe followlng lmporLanL CC Loplcs:
lnherlLance
olymorphlsm
LncapsulaLlon
Note! C# ls case-senslLlve.
4.2. uaLa 1ypes and varlables
20 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
varlables" are slmply sLorage locaLlons for daLa. ?ou can place daLa lnLo Lhem and reLrleve
Lhelr conLenLs as parL of a C# expresslon. 1he lnLerpreLaLlon of Lhe daLa ln a varlable ls
conLrolled Lhrough 1ypes".
1he C# slmple Lypes conslsL of:
8oolean Lype
numerlc Lypes: lnLegrals, lloaLlng olnL, ueclmal
SLrlng Lype
4.2.1. 8oolean Lype
8oolean Lypes are declared uslng Lhe keyword bool". 1hey have Lwo values: Lrue" or
false". ln oLher languages, such as C and C++, boolean condlLlons can be saLlsfled where 0
means false and anyLhlng else means Lrue. Powever, ln C# Lhe only values LhaL saLlsfy a
boolean condlLlon ls Lrue and false, whlch are offlclal keywords.
Lxamp|e:
bool content = true;
bool noContent = false;
4.2.2. numerlc Lypes: lnLegrals, lloaLlng olnL,
ueclmal
Lxamp|e:
int i=35;
long y=654654;

float x;
double y;
decimal z;
4.2.3. SLrlng Lype
Lxamp|e:
string myString=Hei p deg;

Speclal characLers LhaL may be used ln sLrlngs:
21 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#


4.2.4. Arrays
Lxamp|e:
int[] myInts = { 5, 10, 15 };
4.3. ConLrol llow
1o be able Lo conLrol Lhe flow ln your program ls lmporLanL ln every programmlng language.
1he Lwo mosL lmporLanL Lechnlques are:
1he |f SLaLemenL
1he sw|tch SLaLemenL
4.3.1. 1he lf SLaLemenL
1he lf sLaLemenL ls probably Lhe mosL used mechanlsm Lo conLrol Lhe flow ln your
appllcaLlon.
An lf sLaLemenL allows you Lo Lake dlfferenL paLhs of loglc, dependlng on a glven condlLlon.
When Lhe condlLlon evaluaLes Lo a boolean Lrue, a block of code for LhaL Lrue condlLlon wlll
execuLe. ?ou have Lhe opLlon of a slngle lf sLaLemenL, mulLlple else lf sLaLemenLs, and an
opLlonal else sLaLemenL.
Lxamp|e:
bool myTest;
22 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

myTest=false;

if (myTest==false)
MessageBox.Show("Hello");
lf we have more Lhan one llne of code LhaL LhaL shall be execuLed, we need Lo use braces,
e.g.:
bool myTest;

myTest=false;

if (myTest == false)
{
MessageBox.Show("Hello1");
MessageBox.Show("Hello2");
}
lor more complex loglc we use Lhe |f . e|se sLaLemenL.
Lxamp|e:
bool myTest;

myTest=true;


if (myTest == false)
{
MessageBox.Show("Hello1");
}
else
{
MessageBox.Show("Hello2");
}
Cr you can use nested |f. e|se lf senLences.
Lxamp|e:
int myTest;

myTest=2;

if (myTest == 1)
{
MessageBox.Show("Hello1");
}
else if (myTest == 2)
{
MessageBox.Show("Hello2");
}
else
{
MessageBox.Show("Hello3");
}
4.3.2. 1he swlLch SLaLemenL
AnoLher form of selecLlon sLaLemenL ls Lhe sw|tch sLaLemenL, whlch execuLes a seL of loglc
dependlng on Lhe value of a glven parameLer. 1he Lypes of Lhe values a swlLch sLaLemenL
operaLes on can be booleans, enums, lnLegral Lypes, and sLrlngs.
23 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
Lxamp|e:
switch (myTest)
{
case 1:
MessageBox.Show("Hello1");
break;

case 2:
MessageBox.Show("Hello2");
break;

default:
MessageBox.Show("Hello3");
break;
}
4.4. Loops
ln C# we have dlfferenL klnd of loops:
1he whlle loop
1he do loop
1he for loop
1he foreach loop
4.4.1. 1he whlle Loop
A whlle loop wlll check a condlLlon and Lhen conLlnues Lo execuLe a block of code as long as
Lhe condlLlon evaluaLes Lo a boolean value of Lrue.
Lxamp|e:
int myInt = 0;

while (myInt < 10)
{
MessageBox.Show("Inside Loop: " + myInt.ToString());
myInt++;
}
MessageBox.Show("Outside Loop: " + myInt.ToString());
4.4.2. 1he do Loop
A do loop ls slmllar Lo Lhe whlle loop, excepL LhaL lL checks lLs condlLlon aL Lhe end of Lhe
loop. 1hls means LhaL Lhe do loop ls guaranLeed Lo execuLe aL leasL one Llme. Cn Lhe oLher
hand, a whlle loop evaluaLes lLs boolean expresslon aL Lhe beglnnlng and Lhere ls generally
no guaranLee LhaL Lhe sLaLemenLs lnslde Lhe loop wlll be execuLed, unless you program Lhe
code Lo expllclLly do so.
Lxamp|e:
24 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
int myInt = 0;

do
{
MessageBox.Show("Inside Loop: " + myInt.ToString());
myInt++;
} while (myInt < 10);
MessageBox.Show("Outside Loop: " + myInt.ToString());
4.4.3. 1he for Loop
A for loop works llke a whlle loop, excepL LhaL Lhe synLax of Lhe for loop lncludes
lnlLlallzaLlon and condlLlon modlflcaLlon. for loops are approprlaLe when you know exacLly
how many Llmes you wanL Lo perform Lhe sLaLemenLs wlLhln Lhe loop.
Lxamp|e:
for (int i = 0; i < 10; i++)
{
MessageBox.Show("Inside Loop: " + myInt.ToString());
myInt++;
}
MessageBox.Show("Outside Loop: " + myInt.ToString());
4.4.4. 1he foreach Loop
A foreach loop ls used Lo lLeraLe Lhrough Lhe lLems ln a llsL. lL operaLes on arrays or
collecLlons.
Lxamp|e:
string[] names = { "Elvis", "Beatles", "Eagles", "Rolling Stones" };

foreach (string person in names)
{
MessageBox.Show(person);
}
4.3. MeLhods
MeLhods are exLremely useful because Lhey allow you Lo separaLe your loglc lnLo dlfferenL
unlLs. ?ou can pass lnformaLlon Lo meLhods, have lL perform one or more sLaLemenLs, and
reLrleve a reLurn value. 1he capablllLy Lo pass parameLers and reLurn values ls opLlonal and
depends on whaL you wanL Lhe meLhod Lo do.
MeLhods are slmllar Lo funcLlons, procedure or subrouLlne used ln oLher programmlng
languages. 1he dlfference ls LhaL a meLhod ls always a parL of a class.
Lxamp|e:
public void ShowCarColor(string color)
23 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
{

MessageBox.Show("My Car is: " + color);

}
We learn more abouL meLhods ln Lhe Classes secLlon below.
We have 2 klnds of MeLhods:
SLaLlc MeLhods
nonsLaLlc MeLhods (lnsLance MeLhod)
SLaLlc MeLhods belongs Lo Lhe whole class, whlle nonsLaLlc MeLhods belong Lo each lnsLance
creaLed from Lhe class.
4.3.1. nonsLaLlc MeLhods
Lxamp|e:
We deflne Lhe class:
class Car
{

//Nonstatic/Instance Method
public void SetColor(string color)
{

MessageBox.Show("My Car is: " + color);

}
}
1hen we use lL:
Car myCar = new Car(); //We create an Instance of the Class

myCar.SetColor("blue"); //We call the Method
4.3.2. SLaLlc MeLhods
Lxamp|e:
We deflne Lhe class:
class Boat
{

//Static Method
public static void SetColor(string color)
{

MessageBox.Show("My Boat is: " + color);

}
}
26 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
1hen we use lL:
Boat.SetColor("green");
l.e., we don'L need Lo creaLe an ob[ecL/lnsLanLlaLlng Lhe class before we use Lhe SLaLlc
MeLhod.
4.6. namespaces
namespaces are C# program elemenLs deslgned Lo help you organlze your programs. 1hey
also provlde asslsLance ln avoldlng name clashes beLween Lwo seLs of code. lmplemenLlng
namespaces ln your own code ls a good hablL because lL ls llkely Lo save you from problems
laLer when you wanL Lo reuse some of your code.
?ou speclfy Lhe namespaces you wanL Lo use ln Lhe Lop of your code.
Lxamp|e:
When you creaLe a new Wlndows lorms appllcaLlon, Lhe followlng defaulL namespaces wlll
be lncluded.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

lL ls [usL Lo add more when you need lL.
More abouL namespaces laLer.
4.7. Classes
1he flrsL sLep ln CC ls Lo ldenLlfy all Lhe ob[ecLs you wanL Lo manlpulaLe and how Lhey
relaLe Lo each oLher, an exerclse ofLen known as daLa modellng. Cnce you've ldenLlfled an
ob[ecL, you generallze lL as a class of ob[ecLs and deflne Lhe klnd of daLa lL conLalns and any
loglc sequences LhaL can manlpulaLe lL. Lach dlsLlncL loglc sequence ls known as a meLhod. A
real lnsLance of a class ls called an ob[ecL" or an lnsLance of a class". 1he ob[ecL or class
lnsLance ls whaL you run ln Lhe compuLer. lLs meLhods provlde compuLer lnsLrucLlons and
Lhe class ob[ecL characLerlsLlcs provlde relevanL daLa. ?ou communlcaLe wlLh ob[ecLs - and
Lhey communlcaLe wlLh each oLher.
27 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
LveryLhlng ln C# ls based on Classes. Classes are declared by uslng Lhe keyword class
followed by Lhe class name and a seL of class members surrounded by curly braces.
A class normally conslsLs of MeLhods, llelds and roperLles.
Lvery class has a consLrucLor, whlch ls called auLomaLlcally any Llme an lnsLance of a class ls
creaLed. 1he purpose of consLrucLors ls Lo lnlLlallze class members when an lnsLance of Lhe
class ls creaLed. ConsLrucLors do noL have reLurn values and always have Lhe same name as
Lhe class.
Lxamp|e:
We deflne Lhe followlng class:
class Car
{

public string color; //Field

//Method
public void ShowCarColor()
{

MessageBox.Show("My Car is: " + color);

}
}
1hen we can use lL:
Car myCar = new Car(); //We create an Instance of the Class

myCar.color = "blue"; //We set a value for the color Field

myCar.ShowCarColor(); //We call the Method
1he resulL ls as follows:

4.7.1. ConsLrucLor
1he purpose of consLrucLors ls Lo lnlLlallze class members when an lnsLance of Lhe class ls
creaLed.
Lxamp|e:
We can use a ConsLrucLor Lo creaLe a defaulL" color for our car.
We deflne Lhe class:
28 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
class Car
{

public string color; //Field


//Constructor - Used to initialize the Class
public Car()
{
color="green";
}


//Method
public void ShowCarColor()
{

MessageBox.Show("My Car is: " + color);

}
}
1hen we can use lL:
Car myCar = new Car(); //We create an Instance of the Class

myCar.ShowCarColor(); //We call the Method

myCar.color = "blue"; //We set a value for the color Field

myCar.ShowCarColor(); //We call the Method
1he resulLs are as follows:

.

Lxamp|e:
We can also do Lhe followlng:
class Car
{

public string color; //Field


//Constructor - Used to initialize the Class
public Car(string initColor)
{
color = initColor;
29 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
}


//Method
public void ShowCarColor()
{

MessageBox.Show("My Car is: " + color);

}
}
1hen we use lL:
Car myCar = new Car("green"); //We create an Instance of the Class

myCar.ShowCarColor(); //We call the Method
New feature: In|t|a||zat|on an ob[ect w|thout a Constructor:
ln C# 4.0 we can do Lhe followlng:
We deflne Lhe Class (wlLhouL any conLrucLor):
class Car
{

public string color; //Field
public string model; //Field

//Method
public void ShowCarColor()
{

MessageBox.Show("My Car Color is: " + color);
MessageBox.Show("My Car Model is: " + model);

}
}
1hen we do Lhe followlng:
Car myCar = new Car {color="white", model="2004"};

myCar.ShowCarColor(); //We call the Method
4.8. roperLles
roperLles provlde Lhe opporLunlLy Lo proLecL a fleld ln a class by readlng and wrlLlng Lo lL
Lhrough Lhe properLy. ln oLher languages, Lhls ls ofLen accompllshed by programs
lmplemenLlng speclallzed geLLer and seLLer meLhods. C# properLles enable Lhls Lype of
proLecLlon whlle also leLLlng you access Lhe properLy [usL llke lL was a fleld.
Lxamp|e:
We deflne a Class wlLh roperLles and a MeLhod:
class Car
{

30 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
public string Name {get; set;}
public string Color {get; set;}

public void ShowCarProperties()
{

MessageBox.Show("My Car Name is: " + Name);
MessageBox.Show("My Car Color is: " + Color);

}

}
1hen we can use lL:
Car myCar = new Car();

myCar.Name="Volvo";
myCar.Color="Blue";


myCar.ShowCarProperties();
1he resulLs are:

.

So far, Lhe only class members you've seen are llelds, roperLles, MeLhods, and
ConsLrucLors. Pere ls a compleLe llsL of Lhe Lypes of members you can have ln your classes:
Constructors
uesLrucLors (opposlLe of ConsLrucLors)
I|e|ds
Methods
ropert|es
lndexers
uelegaLes
Lvents
nesLed Classes
31 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
4.9. namlng ConvenLlon
1here ls dlfferenL name convenLlon for how Lo speclfy your varlables, classes and MeLhods,
eLc.
Came| notat|on:
lor var|ab|es and parameters]arguments we normally use Camel noLaLlon".
Lxamp|es:
string myCar;
int number;
string backColor;
- ln Camel caslng Lhe flrsL leLLer of an ldenLlfler ls lowercase and Lhe flrsL leLLer of each
subsequenL concaLenaLed word ls caplLallzed.
asca| notat|on:
lor c|asses, methods and propert|es, we normally use ascal noLaLlon".
Lxamp|es:
class Car
{
void ShowCarColor()
{

}
}
- ln ascal caslng Lhe flrsL leLLer ln Lhe ldenLlfler and Lhe flrsL leLLer of each subsequenL
concaLenaLed word are caplLallzed.
lor namespaces we use ascal caslng and a doL separaLor.
Lxamp|es:
System.Drawing
System.Collections.Generics
Contro|s:
lor conLrols on your user lnLerface we elLher use ascal noLaLlon" or Pungarlan noLaLlon",
buL sLlck Lo one of Lhem!
Lxamp|es:
ascal noLaLlon":
LoginName
LoginPassword
32 CeLLlng SLarLed wlLh C#
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
Pungarlan noLaLlon":
txtName
txtPassword
lblName
btnCancel
Where LxL" means lL ls a 1exL ConLrol, lbl" a Label ConLrol, bLn" a 8uLLon ConLrol, eLc.
Acronyms:
Caslng of acronyms depends on Lhe lengLh of Lhe acronym. All acronyms are aL leasL Lwo
characLers long. lf an acronym ls exacLly Lwo characLers, lL ls consldered a shorL acronym. An
acronym of Lhree or more characLers ls a long acronym.
ln general, you should noL use abbrevlaLlons or acronyms. 1hese make your names less
readable. Slmllarly, lL ls dlfflculL Lo know when lL ls safe Lo assume LhaL an acronym ls wldely
recognlzed.
8uL lf you musL, Lhe rules are as follows:
Short acronym Lxamp|es (two characters):
DBRate
A properLy named u88aLe ls an example of a shorL acronym (u8) used as Lhe flrsL word of a
ascal-cased ldenLlfler.
ioChannel
A parameLer named loChannel ls an example of a shorL acronym (lC) used as Lhe flrsL word
of a camel-cased ldenLlfler.
Long acronym Lxamp|es (three or more characters):
XmlWriter
A class named xmlWrlLer ls an example of a long acronym used as Lhe flrsL word of a
ascal-cased ldenLlfler.
htmlReader
A parameLer named hLml8eader ls an example of a long acronym used as Lhe flrsL word of a
camel-cased ldenLlfler.



33

3. More Cb[ecL-orlenLed
1echnlques
ln Lhls chapLer we wlll lnLroduce Lhe followlng Cb[ecL-orlenLed Lechnlques:
lnherlLance
olymorphlsm
LncapsulaLlon
3.1. lnherlLance
lnherlLance ls one of Lhe prlmary concepLs of ob[ecL-orlenLed programmlng. lL allows you Lo
reuse exlsLlng code. 1hrough effecLlve employmenL of reuse, you can save Llme ln your
programmlng.
Lxample:
We deflne Lhe 8ase class:
class Car
{

public void SetColor(string color)
{

MessageBox.Show("My Car is: " + color);

}
}
1hen we deflne a new class LhaL lnherlLs from Lhe 8ase Class:
class Volvo : Car
{

//In this simple Example this class does nothing!

}
1hen we sLarL uslng Lhe classes:
Car myCar = new Car();
myCar.SetColor("blue");


Volvo myVolvo = new Volvo();
34 More Cb[ecL-orlenLed 1echnlques
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
myVolvo.SetColor("green");
As you can see we can use Lhe SeLColor()" MeLhod LhaL has been deflned ln Lhe 8ase Class.
3.2. olymorphlsm
AnoLher prlmary concepL of ob[ecL-orlenLed programmlng ls olymorphlsm. lL allows you Lo
lnvoke derlved class meLhods Lhrough a base class reference durlng run-Llme.
Lxamp|e:
We sLarL wlLh a 8ase Class:
class Car
{
public virtual void CarType()
{
MessageBox.Show("I am a Car");
}
}
1he vlrLual modlfler lndlcaLes Lo derlved classes LhaL Lhey can overrlde Lhls meLhod.
1hen we creaLe 3 new Classes LhaL derlve from Lhe 8ase Class:
class Volvo : Car
{
public override void CarType()
{
MessageBox.Show("I am a Volvo");
}
}


class Ford : Car
{
public override void CarType()
{
MessageBox.Show("I am a Ford");
}
}


class Toyota : Car
{
public override void CarType()
{
MessageBox.Show("I am a Toyota");
}
}
1hese 3 classes lnherlL Lhe Car class. Lach class has a Car1ype() meLhod and each Car1ype()
meLhod has an overrlde modlfler. 1he overrlde modlfler allows a meLhod Lo overrlde Lhe
vlrLual meLhod of lLs base class aL run-Llme.
1hen we can use lL:
Car[] car = new Car[4];

car[0] = new Car();
33 More Cb[ecL-orlenLed 1echnlques
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
car[1] = new Volvo();
car[2] = new Ford();
car[3] = new Toyota();


foreach (Car carmodel in car)
{
carmodel.CarType();
}
1he resulL ls:
. . .
- 1hls ls olymorphlsm.
3.3. LncapsulaLlon
LncapsulaLlon means LhaL Lhe lnLernal represenLaLlon of an ob[ecL ls generally hldden from
vlew ouLslde of Lhe ob[ecL's deflnlLlon. 1yplcally, only Lhe ob[ecL's own meLhods can dlrecLly
lnspecL or manlpulaLe lLs flelds.
We can seL dlfferenL Access rlghLs on Classes and MeLhods:




36

6. LxcepLlon Pandllng
ln programmlng error and excepLlon handllng ls very lmporLanL. C# has bullL-ln and ready Lo
use mechanlsm Lo handle Lhls. 1hls mechanlsm ls based on Lhe keywords !"#, $%!$&, !&"'(
and )*+%,,#.
LxcepLlons are unforeseen errors LhaL happen ln your programs. MosL of Lhe Llme, you can,
and should, deLecL and handle program errors ln your code. lor example, valldaLlng user
lnpuL, checklng for null ob[ecLs, and verlfylng Lhe values reLurned from meLhods are whaL
you expecL, are all examples of good sLandard error handllng LhaL you should be dolng all Lhe
Llme.
Powever, Lhere are Llmes when you don'L know lf an error wlll occur. lor example, you can'L
predlcL when you'll recelve a flle l/C error, run ouL of sysLem memory, or encounLer a
daLabase error. 1hese Lhlngs are generally unllkely, buL Lhey could sLlll happen and you wanL
Lo be able Lo deal wlLh Lhem when Lhey do occur. 1hls ls where excepLlon handllng comes ln.
When excepLlons occur, Lhey are sald Lo be Lhrown". C# uses Lhe keywords !"#, $%!$&, !&"'(
and )*+%,,#. lL works llke Lhls: A meLhod wlll Lry Lo execuLe a plece of code. lf Lhe code deLecLs
a problem, lL wlll !&"'( an error lndlcaLlon, whlch your code can $%!$&, and no maLLer whaL
happens, lL )*+%,,# execuLes a speclal code block aL Lhe end.
1he synLax ls as follows:
MyMethod()
{

try
{
... //Do Something that can cause an Exception
}
catch
{
... //Handle Exceptions
}

finally
{
... //Clean Up
}

}
Lxamp|e:
public void WriteDaqData(double analogDataOut)
{


Task analogOutTask = new Task();
37 LxcepLlon Pandllng
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

AOChannel myAOChannel;

try
{

myAOChannel = analogOutTask.AOChannels.CreateVoltageChannel(
aoChannel,
"myAOChannel",
0,
5,
AOVoltageUnits.Volts
);

AnalogSingleChannelWriter writer = new
AnalogSingleChannelWriter(analogOutTask.Stream);

writer.WriteSingleSample(true, analogDataOut);
}
catch (Exception e)
{
string errorMessage;

errorMessage = e.Message.ToString();

}

finally
{
analogOutTask.Stop();
}

}



38

7. Wlndows lorms
Lxample
ln Lhls chapLer we wlll go Lhrough a large example. ln Lhls example we wlll creaLe an
appllcaLlon ln vlsual SLudlo LhaL conLrols Lhe followlng waLer Lank process:


1he purpose ls Lo conLrol Lhe level ln Lhe waLer Lank. ln order Lo communlcaLe wlLh Lhe
physlcal process we use a nl uS8-6008 uAC devlce:

We wlll noL show all Lhe deLalls ln Lhe code, buL focus on Lhe sLrucLure.
8elow we see Lhe user lnLerface we have creaLed ln vlsual SLudlo:
39 Wlndows lorms Lxample
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#


8elow we see Lhe vlsual SLudlo pro[ecL:


We sLarL wlLh deflnlng Lhe classes we need ln our appllcaLlon.
ln Lhe SoluLlon Lxplorer we have deflned a Classes" folder where we puL all Lhe classes we
creaLe:
40 Wlndows lorms Lxample
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

ln order Lo creaLe new classes we rlghL-cllck ln Lhe SoluLlon Lxplorer and selecL Add-new
lLem.":


nexL we selecL Lhe C|ass lLem ln Lhe Add new lLem" wlndow:
41 Wlndows lorms Lxample
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

C|asses:
We sLarL wlLh Lhe uaq" Class LhaL conLalns loglc for readlng and wrlLlng Lo Lhe uAC devlce:
//Include necessary Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NationalInstruments;
using NationalInstruments.DAQmx;

namespace Tuc.Control //We define a useful namespace
{
public class DaqData
{

public string aiChannel;
public string aoChannel;


//Constructor
public DaqData(...)
{
...
}


//Method
public double ReadDaqData()
{
...
}


//Method
public void WriteDaqData(...)
{
...
}
}
}
42 Wlndows lorms Lxample
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
lL ls good pracLlce Lo creaLe a new flle for each new class we deflne. 1hen we sLarL by
deflnlng a meanlngful namespace. nexL we deflne our Class wlLh necessary llelds,
roperLles and MeLhods.
We also need Lo lnclude Lhe necessary namespace our Class wlll need. ln Lhls example we
have lncluded some 3.parLy Assemblles from naLlonal lnsLrumenLs:
using NationalInstruments;
using NationalInstruments.DAQmx;
1hese Assemblles conLalns Lhe drlver Lo Lhe nl uS8-6008 uAC devlce we are uslng.
1he Assemblles we use musL be added ln Lhe 8eferences" folder ln Lhe SoluLlon Lxplorer:


Ma|n App||cat|on:
ln our maln appllcaLlon we sLarL wlLh lncludlng our namespace:
using NationalInstruments;
using NationalInstruments.UI;
using NationalInstruments.UI.WindowsForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tuc.Control;


namespace Control_Application
{
public partial class Form1 : Form
{
...
}
}
43 Wlndows lorms Lxample
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
lL ls also a good ldea Lo creaLe dlfferenL reglons ln order Lo sLrucLure your code beLLer. 1hls
can be done llke Lhls:
//Comment
" #$%&'(
... //Your Code
" $()#$%&'(
ln Lhls way our Maln AppllcaLlon may look llke Lhls:





44

8. Web rogrammlng
8.1. lnLroducLlon
1oday mosL of Lhe appllcaLlons focus on Lhe lnLerneL, where Lhe appllcaLlons can be vlewed
ln a sLandard Web 8rowser. SLaLlc Web pages are based on P1ML and CSS. ln order Lo creaLe
more advanced appllcaLlons, we need more powerful Lools.
lmporLanL frameworks and Lools for creaLlng dynamlc web pages:
AS.nL1
A!Ax/ AS.nL1 A!Ax
!avaScrlpL
SllverllghL
1hese frameworks and Lools wlll be explalned below.
See Lhe 1uLorlal AS.nL1 and Web rogrammlng" for more deLalls.
8.2. P1ML
P1ML, whlch sLands for Pyper1exL Markup Language, ls Lhe predomlnanL markup language
for web pages. P1ML ls Lhe baslc bulldlng-blocks of webpages.
P1ML ls wrlLLen ln Lhe form of P1ML elemenLs conslsLlng of Lags, enclosed ln angle brackeLs
(llke <hLml>), wlLhln Lhe web page conLenL. P1ML Lags normally come ln palrs llke <h1> and
</h1>. 1he flrsL Lag ln a palr ls Lhe sLarL Lag, Lhe second Lag ls Lhe end Lag (Lhey are also
called openlng Lags and closlng Lags). ln beLween Lhese Lags web deslgners can add LexL,
Lables, lmages, eLc.
8.3. Web 8rowser
1he purpose of a web browser ls Lo read P1ML documenLs and compose Lhem lnLo vlsual or
audlble web pages. 1he browser does noL dlsplay Lhe P1ML Lags, buL uses Lhe Lags Lo
lnLerpreL Lhe conLenL of Lhe page.
43 Web rogrammlng
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#
1oday we have Lhe followlng ma[or Web 8rowsers:
lnLerneL Lxplorer (by MlcrosofL)
llrefox (by Mozllla)
Chrome (by Coogle)
Safarl (by Apple)
Cpera (by Cpera from norway)
8.4. CSS
Web browsers can also refer Lo Cascadlng SLyle SheeLs (CSS) Lo deflne Lhe appearance and
layouL of LexL and oLher maLerlal.
1he W3C, malnLalner of boLh Lhe P1ML and Lhe CSS sLandards
8.3. !avaScrlpL
!avaScrlpL ls an ob[ecL-orlenLed scrlpLlng language baslcally used Lo creaLe dynamlc web
pages. !avaScrlpL ls prlmarlly used ln Lhe form of cllenL-slde !avaScrlpL, lmplemenLed as parL
of a web browser ln order Lo provlde enhanced user lnLerfaces and dynamlc webslLes.
8.6. AS.nL1
AS.nL1 ls a web appllcaLlon framework developed by MlcrosofL Lo allow programmers Lo
bulld dynamlc web slLes, web appllcaLlons and web servlces.
AS.nL1 ls parL of Lhe vlsual SLudlo package
lL was flrsL released ln !anuary 2002 wlLh verslon 1.0 of Lhe .nL1 lramework, and ls Lhe
successor Lo MlcrosofL's AcLlve Server ages (AS) Lechnology. AS.nL1 ls bullL on Lhe
Common Language 8unLlme (CL8), allowlng programmers Lo wrlLe AS.nL1 code uslng any
supporLed .nL1 language, such as C# and v8.nL1.
AS.nL1 web pages or webpage, known offlclally as Web lorms], are Lhe maln bulldlng block
for appllcaLlon developmenL. Web forms are conLalned ln flles wlLh an .aspx" exLenslon.
SelecL AS.nL1 AppllcaLlon" ln Lhe new ro[ecL" wlndow:
46 Web rogrammlng
1uLorlal: lnLroducLlon Lo vlsual SLudlo and C#

8.7. A!Ax/ AS.nL1 A!Ax
AIAk ls an acronym for Asynchronous !avaScrlpL and xML. A!Ax ls a group of lnLerrelaLed
web developmenL meLhods used on Lhe cllenL-slde Lo creaLe lnLeracLlve web appllcaLlons.
WlLh A[ax, web appllcaLlons can send daLa Lo, and reLrleve daLa from, a server
asynchronously (ln Lhe background) wlLhouL lnLerferlng wlLh Lhe dlsplay and behavlor of Lhe
exlsLlng page.
AS.NL1 AIAk ls a seL of exLenslons Lo AS.nL1 developed by MlcrosofL for lmplemenLlng
A!Ax funcLlonallLy.
8.8. SllverllghL
MlcrosofL SllverllghL ls an appllcaLlon framework for wrlLlng and runnlng browser plug-lns or
oLher rlch lnLerneL appllcaLlons, wlLh feaLures and purposes slmllar Lo Lhose of Adobe llash.
1he run-Llme envlronmenL for SllverllghL ls avallable as a plug-ln for mosL web browsers.
SllverllghL ls also one of Lhe Lwo appllcaLlon developmenL plaLforms for Wlndows hone 7/8.
1he laLesL verslon ls SllverllghL 3.0.
SllverllghL ls based on Wl, so ln SllverllghL appllcaLlons, user lnLerfaces are declared ln
LxLenslble AppllcaLlon Markup Language (xAML) and programmed uslng a subseL of Lhe .nL1
lramework.

47

9. uaLabase rogrammlng
MosL of Loday's appllcaLlons use a backend daLabase Lo sLore lmporLanL daLa, e.g., lacebook,
1wlLLer, eLc.
ln order Lo use daLabases ln our appllcaLlons we need Lo know Structured uery |anguage
(SL). lor more lnformaLlon abouL SCL, see Lhe followlng 1uLorlal:
Structured uery Language (SL)
ln addlLlon you need Lo know abouL daLabase sysLems. We have dlfferenL klnd of daLabase
sysLems and loLs of dlfferenL vendors. Slnce Lhls 1uLorlal ls abouL vlsual SLudlo and C#, we
wlll use M|crosoft SL Server. lor more lnformaLlon abouL daLabase sysLems ln general and
speclally SCL Server, see Lhe followlng 1uLorlal:
Introduct|on to Database Systems
1he 1uLorlals are avallable from: http:]]home.h|t.no]~hansha
9.1. AuC.nL1
AuC.nL1 (AcLlvex uaLa Cb[ecL for .nL1) ls a seL of compuLer sofLware componenLs LhaL
programmers can use Lo access daLa and daLa servlces. lL ls a parL of Lhe base class llbrary
LhaL ls lncluded wlLh Lhe MlcrosofL .nL1 lramework. lL ls commonly used by programmers Lo
access and modlfy daLa sLored ln relaLlonal daLabase sysLems, Lhough lL can also access daLa
ln non-relaLlonal sources.








1e|emark Un|vers|ty Co||ege
Iacu|ty of 1echno|ogy
k[|nes k|ng S6
N-3914 orsgrunn, Norway
www.h|t.no


nans-etter na|vorsen, M.Sc.
1e|emark Un|vers|ty Co||ege
Iacu|ty of 1echno|ogy
Department of L|ectr|ca| Lng|neer|ng, Informat|on 1echno|ogy and Cybernet|cs

L-ma||: hans.p.ha|vorsenQh|t.no
8|og: http:]]home.h|t.no]~hansha]

You might also like