diff --git a/CSHARP/Lessons.md b/CSHARP/Lessons.md index 6d304c4..66ed355 100644 --- a/CSHARP/Lessons.md +++ b/CSHARP/Lessons.md @@ -20,4 +20,73 @@ class Person } } -=== === \ No newline at end of file +=== Конструкторы, инициализаторы и деконструкторы === + +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}"); +} \ No newline at end of file diff --git a/CSHARP/Program.cs b/CSHARP/Program.cs index d3f2321..6f7e0e6 100644 --- a/CSHARP/Program.cs +++ b/CSHARP/Program.cs @@ -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}"); } \ No newline at end of file diff --git a/CSHARP/bin/Debug/net9.0/CSHARP.dll b/CSHARP/bin/Debug/net9.0/CSHARP.dll index 8b40bd9..651f8dc 100644 Binary files a/CSHARP/bin/Debug/net9.0/CSHARP.dll and b/CSHARP/bin/Debug/net9.0/CSHARP.dll differ diff --git a/CSHARP/bin/Debug/net9.0/CSHARP.exe b/CSHARP/bin/Debug/net9.0/CSHARP.exe index 895f6f8..4078372 100644 Binary files a/CSHARP/bin/Debug/net9.0/CSHARP.exe and b/CSHARP/bin/Debug/net9.0/CSHARP.exe differ diff --git a/CSHARP/bin/Debug/net9.0/CSHARP.pdb b/CSHARP/bin/Debug/net9.0/CSHARP.pdb index e3e5302..eff4e44 100644 Binary files a/CSHARP/bin/Debug/net9.0/CSHARP.pdb and b/CSHARP/bin/Debug/net9.0/CSHARP.pdb differ diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs index a3fcc4f..dd4bab4 100644 --- a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs +++ b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs @@ -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")] diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache index 2c96909..9850935 100644 --- a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache +++ b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache @@ -1 +1 @@ -8b42992521c44adabdfff2f0c94aca9302acbb4a3d22a089bd2074043d71fed8 +8e1d40d7011353f00b3998c361926632fbcce86fc7b441528c4e189b70a28f7a diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.dll b/CSHARP/obj/Debug/net9.0/CSHARP.dll index 8b40bd9..651f8dc 100644 Binary files a/CSHARP/obj/Debug/net9.0/CSHARP.dll and b/CSHARP/obj/Debug/net9.0/CSHARP.dll differ diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.pdb b/CSHARP/obj/Debug/net9.0/CSHARP.pdb index e3e5302..eff4e44 100644 Binary files a/CSHARP/obj/Debug/net9.0/CSHARP.pdb and b/CSHARP/obj/Debug/net9.0/CSHARP.pdb differ diff --git a/CSHARP/obj/Debug/net9.0/apphost.exe b/CSHARP/obj/Debug/net9.0/apphost.exe index 895f6f8..4078372 100644 Binary files a/CSHARP/obj/Debug/net9.0/apphost.exe and b/CSHARP/obj/Debug/net9.0/apphost.exe differ diff --git a/CSHARP/obj/Debug/net9.0/ref/CSHARP.dll b/CSHARP/obj/Debug/net9.0/ref/CSHARP.dll index 01f285b..df207d6 100644 Binary files a/CSHARP/obj/Debug/net9.0/ref/CSHARP.dll and b/CSHARP/obj/Debug/net9.0/ref/CSHARP.dll differ diff --git a/CSHARP/obj/Debug/net9.0/refint/CSHARP.dll b/CSHARP/obj/Debug/net9.0/refint/CSHARP.dll index 01f285b..df207d6 100644 Binary files a/CSHARP/obj/Debug/net9.0/refint/CSHARP.dll and b/CSHARP/obj/Debug/net9.0/refint/CSHARP.dll differ