C Sharp/Programowanie obiektowe: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Codern (dyskusja | edycje)
Nie podano opisu zmian
Codern (dyskusja | edycje)
Nie podano opisu zmian
Linia 34:
:int x;
:int y;
:void show()
:{
::Console.WriteLine("X:"+this.x+"Y:"+this.y);
:}
}
</code>
 
==Konstruktor==
 
Jest to specjalna metoda wywoływana przy tworzeniu nowego obiektu klasy. Ta metoda ma taką samą nazwę jak nazwa klasy.
 
Dodajmy do naszej klasy konstruktor:
<code>
public
class Klasa
{
:int x;
:int y;
:public Punkt(int x,int y)
:{
::this.x=x;
::this.y=y;
:}
:void show()
:{