Половина урока 3.2

This commit is contained in:
deadzilla 2026-04-28 23:14:51 +05:00
parent 2101d584f3
commit a385581ef2
12 changed files with 81 additions and 15 deletions

View File

@ -20,4 +20,73 @@ class Person
}
}
=== ===
=== Конструкторы, инициализаторы и деконструкторы ===
Person tom = new Person();
Person bob = new Person("Bob");
Person sam = new Person("Sam", 25);
tom.Print();
bob.Print();
sam.Print();
class Person
{
public string name;
public int age;
public Person()
{
name = "Unknown";
age = 18;
}
public Person(string n) { name = n; age = 18; }
public Person(string n, int a) { name = n; age = a; }
public void Print()
{
Console.WriteLine($"name: {name} age: {age}");
}
}
Person sam = new Person("Sam", 25);
sam.Print();
class Person
{
public string name;
public int age;
public Person()
{
name = "Unknown";
age = 18;
}
public Person(string name) { this.name = name; age = 18; }
public Person(string name, int age)
{
this.name = name;
this.age = age;
}
public void Print()
{
Console.WriteLine($"name: {name} age: {age}");
}
}
"Цепочка вызова конструкторов"
Person sam = new Person("Sam", 25);
sam.Print();
class Person
{
public string name;
public int age;
public Person() : this("Unknown") { }
public Person(string name) : this(name, 18) { }
public Person(string name, int age)
{
this.name = name;
this.age = age;
}
public void Print() => Console.WriteLine($"Name: {name} Age: {age}");
}

View File

@ -1,19 +1,16 @@
Person tom = new Person();
string personName = tom.name;
int personAge = tom.age;
Console.WriteLine($"name: {personName} age: {personAge}");
tom.name = "Tom";
tom.age = 37;
tom.Print();
Person sam = new Person("Sam", 25);
sam.Print();
class Person
{
public string name = "Undefined";
public string name;
public int age;
public void Print()
public Person() : this("Unknown") { }
public Person(string name) : this(name, 18) { }
public Person(string name, int age)
{
Console.WriteLine($"Имя: {name} Возраст: {age}");
this.name = name;
this.age = age;
}
public void Print() => Console.WriteLine($"Name: {name} Age: {age}");
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("CSHARP")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+aa050c247f6147a284a534e34522aed399958c7f")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2101d584f338f6f88ae1a4305d8bd8c1bb8d13cf")]
[assembly: System.Reflection.AssemblyProductAttribute("CSHARP")]
[assembly: System.Reflection.AssemblyTitleAttribute("CSHARP")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
8b42992521c44adabdfff2f0c94aca9302acbb4a3d22a089bd2074043d71fed8
8e1d40d7011353f00b3998c361926632fbcce86fc7b441528c4e189b70a28f7a

Binary file not shown.

Binary file not shown.

Binary file not shown.