Professional Documents
Culture Documents
Magasszintű
Programozási Nyelvek I.
Eszterházy Károly Főiskola
Számítástudományi tsz
http://aries.ektf.hu
1
Érték-típusok Típusok
Egészek
Valósak
Logikai
Karakter
String
Referencia-
típusok
Tömbök
Rekordok
Listák
2
Value type (érték-típus)
int a;
50
4
Value type (érték-típus)
Egészek
Érték-típusok
Valósak
Logikai
Karakter
5
Reference type (referencia-típus)
class Hallgato
{
public int eletkor;
public string neve;
public bool ferfi;
}
Hallgato h;
6
Reference type (referencia-típus)
Hallgato h;
7
Reference type (referencia-típus)
Hallgato h;
4 byte
null
String
típusok
Tömbök
Osztályok
9
Reference type (referencia-típus)
h = new Hallgato();
4 byte 1 db Hallgato számára elég byte
h 1
10
Reference type (referencia-típus)
h.eletkor = 20;
Hallgato h;
h.eletkor = 20;
Nem működik, mert a ‘null’ linket nem lehet
követni !
13
Reference type (referencia-típus)
h k
14
Reference type (referencia-típus)
Hallgato k = h;
h 1 2
16
Reference type (referencia-típus)
for(int i=0;i<10;i++)
{
Hallgato h = new Hallgato();
h.nev = Console.ReadLine();
}
Console.WriteLine(h.nev); // ????
Szintaktikai hibás, hiszen a ‘h’ változó a for
blokkján belül lett deklarálva, így a blokkon kívül
nem használható!
17
Reference type (referencia-típus)
Hallgato h;
for(int i=0;i<10;i++)
{
h = new Hallgato();
h.nev = Console.ReadLine();
}
Console.WriteLine(h.nev); // ????
null
t 1
19
Reference type (referencia-típus)
t 1
20
Reference type (referencia-típus)
t 1 2
Ez működik!
21
Reference type (referencia-típus)
Hallgato t = new Hallgato[40];
Ez még csak a 40 darab memóriacím számára foglal le
helyet (40*4 byte), de a tömbelemek egyelőre ‘null’ értékkel
rendelkeznek, így nem használhatóak fel tényleges
adattárolásra!
for(int i=0;i<t.Length;i++)
{
t[i] = new Hallgato();
}
Ezért kell egy ciklus, amely feltölti a tömbelemeket tényleges
memóriacímekkel!
Ez a művelet meg kell előzze a tömbelemek használatát!
22
Reference type (referencia-típus)
double[] t = new double[30];
30 * 8 byte ( 1 double=8 byte)
1 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | … | 0.0
t 1
23
Reference type (referencia-típus)
tomb 1 h
1 H | e | l | l | o | | V | i | l | a | g | ! | \0 1
s 1 m
string m = s;
A másik string változó (‘m’) csak 4 byte-ba kerül, és
ugyanarra a szövegre fog mutatni.
28
Reference type (referencia-típus)
1 Hello Vilag!
s 1
s 1 2
30
Reference type (referencia-típus)
string s = ”Hello Vilag!”
s= s.SubString(3,5); // másolatot hoz létre
2 Hello Vilag! lo Vi
s 1 2
s= s.SubString(3,5).ToUpper();
3 Hello Vilag! lo Vi LO VI
s 1 2 3
31
Reference type (referencia-típus)
string s = ”Hello Vilag!”
s= s + ”Sziasztok!”
s 1 2
32
Reference type (referencia-típus)
s 1 2 3
33