Урок 3.2 завершён

This commit is contained in:
deadzilla 2026-04-29 22:55:25 +05:00
parent a385581ef2
commit 837beff6c4
12 changed files with 70 additions and 13 deletions

View File

@ -90,3 +90,55 @@ class Person
} }
public void Print() => Console.WriteLine($"Name: {name} Age: {age}"); public void Print() => Console.WriteLine($"Name: {name} Age: {age}");
} }
"Первичные конструкторы"
var tom = new Person("Tom", 38);
Console.WriteLine(tom);
public class Person(string name, int age)
{
public Person(string name) : this(name, 18) { }
public void Print() => Console.WriteLine($"name: {name}, age: {age}");
}
"Инициализаторы объектов"
Person tom = new Person { name = "Tom", company = { title = "Microsoft" } };
tom.Print();
class Person
{
public string name;
public Company company;
public Person()
{
name = "Undefinde";
company = new Company();
}
public void Print() => Console.WriteLine($"name: {name} company: {company.title}");
}
class Company
{
public string title = "Unknown";
}
"Деконструкторы"
Person person = new Person("Tom", 33);
(string name, int age) = person; //(_, int age) = person если нужен только возраст
Console.WriteLine(name);
class Person
{
string name;
int age;
public Person(string name, int age)
{
this.name;
this.age;
}
public void Deconstruct(out string personName, out int personAge)
{
personName = name;
personAge = age;
}
}

View File

@ -1,16 +1,21 @@
Person sam = new Person("Sam", 25); Person person = new Person("Tom", 33);
sam.Print(); (string name, int age) = person; //(_, int age) = person если нужен только возраст
Console.WriteLine(name);
class Person class Person
{ {
public string name; string name;
public int age; int age;
public Person() : this("Unknown") { }
public Person(string name) : this(name, 18) { }
public Person(string name, int age) public Person(string name, int age)
{ {
this.name = name; this.name;
this.age = age; this.age;
} }
public void Print() => Console.WriteLine($"Name: {name} Age: {age}"); public void Deconstruct(out string personName, out int personAge)
{
personName = name;
personAge = age;
} }
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("CSHARP")] [assembly: System.Reflection.AssemblyCompanyAttribute("CSHARP")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2101d584f338f6f88ae1a4305d8bd8c1bb8d13cf")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a385581ef2126891ffe561caf708150c6ef0c3cd")]
[assembly: System.Reflection.AssemblyProductAttribute("CSHARP")] [assembly: System.Reflection.AssemblyProductAttribute("CSHARP")]
[assembly: System.Reflection.AssemblyTitleAttribute("CSHARP")] [assembly: System.Reflection.AssemblyTitleAttribute("CSHARP")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Создано классом WriteCodeFragment MSBuild. // Generated by the MSBuild WriteCodeFragment class.

View File

@ -1 +1 @@
8e1d40d7011353f00b3998c361926632fbcce86fc7b441528c4e189b70a28f7a e5d3a2d50b713fd5feb66a02c824290572091f66fdfcd5902a5e5cb105d4cb38

Binary file not shown.

Binary file not shown.

Binary file not shown.