Documente Academic
Documente Profesional
Documente Cultură
METODE
1. Specificatorii de acces
2. Parametri formali și parametri actuali
3. Transferul prametrilor prin valoare și prin referință
1. Constructor/Destructor
1.
1
Notițe METODE ACTIVITĂȚI 3
Specificatorii de acces
sing System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cursul04.ex3
{
class Persoana
{
protected string nume;
protected string prenume;
public Persoana(string nm, string pnm)
{
nume = nm;
prenume = pnm;
}
}
class Program
{
static void Main(string[] args)
{
Angajat el = new Angajat("Popescu", "Ion", 1983);
2
ACTIVITĂȚI 3 METODE Notițe
el.AfiseazaNumeleIntregSiAnulAngajarii();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cursul04.ex4
{
class Dreptunghi
{
int l, L;
int arie;
public Dreptunghi(int i, int j)
{
l = i;
3
Notițe METODE ACTIVITĂȚI 3
L = j;
arie = l * L;
}
public bool Congruent(Dreptunghi obiect)
{
if ((obiect.l == l) & (obiect.L == L))
return true;
else
return false;
}
public bool Echivalent(Dreptunghi obiect)
{
if (obiect.arie == arie)
return true;
else
return false;
}
class Program
{
static void Main(string[] args)
{
}
}
}
}
4
ACTIVITĂȚI 3 METODE Notițe
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cursul05.ex1
{
class Point
{
public double x, y;
public Point(double a, double b)
{
x = a;
y = b;
}
}
class DemoTransferParametri
{
public void PrinValoare(double a, double b)
{
a = a + b;
b = -b;
}
public void PrinReferinta(Point punct)
{
punct.x = punct.x + punct.y;
punct.y = -punct.y;
}
}
class Program
{
static void Main(string[] args)
{
5
Notițe METODE ACTIVITĂȚI 3
DemoTransferParametri();
dtp.PrinValoare(punct1.x, punct1.y);
Console.WriteLine("\nx={0} si y={1} dupa apelul metodei
PrinValoare", punct1.x, punct1.y);
dtp.PrinReferinta(punct1);
Console.WriteLine("\nx={0} si y={1} dupa apelul metodei
PrinRefeinta", punct1.x, punct1.y);
Constructor/Destructor
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
6
ACTIVITĂȚI 3 METODE Notițe
using System.Threading.Tasks;
namespace cursul04.ex5
{
class Point
{
public double x;
public double y;
public Point(double a, double b)
{
x = a;
y = b;
}
~Point()
{
Console.WriteLine("\nDeleting point x={0} y={1}", x,
y);
}
public void GeneratePoint(double i, double j)
{
Point p = new Point(i, j);
}
class Program
{
static void Main(string[] args)
{
int n, m;
int maxPoints = 100;
for (n=1;n<=maxPoints;n++)
for (m=1;m<=maxPoints;m++)
pnm.GeneratePoint(n,m);
}
}
}
7
Notițe METODE ACTIVITĂȚI 3
Ap1
1
…
8
ACTIVITĂȚI 3 METODE Notițe
Print
GetName
PlayMusic
SetUserName
And some examples for bad named methods:
Abc11
9
Notițe METODE ACTIVITĂȚI 3
Yellow___Black
foo
_Bar
It is very important that the method name describes the method’s purpose. All behind
this idea is that when a person that is not familiar with our program reads the method
name, they can easily understand what that method does, without the need to look at
the method’s source code.
10