diff --git a/CSHARP/Lessons.md b/CSHARP/Lessons.md index 66ed355..9311d2a 100644 --- a/CSHARP/Lessons.md +++ b/CSHARP/Lessons.md @@ -89,4 +89,56 @@ class Person this.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; + } } \ No newline at end of file diff --git a/CSHARP/Program.cs b/CSHARP/Program.cs index 6f7e0e6..f68b2f5 100644 --- a/CSHARP/Program.cs +++ b/CSHARP/Program.cs @@ -1,16 +1,21 @@ -Person sam = new Person("Sam", 25); -sam.Print(); +Person person = new Person("Tom", 33); +(string name, int age) = person; //(_, int age) = person если нужен только возраст +Console.WriteLine(name); + class Person { - public string name; - public int age; - public Person() : this("Unknown") { } - public Person(string name) : this(name, 18) { } + string name; + int age; public Person(string name, int age) { - this.name = name; - this.age = age; + this.name; + this.age; } - public void Print() => Console.WriteLine($"Name: {name} Age: {age}"); -} \ No newline at end of file + public void Deconstruct(out string personName, out int personAge) + { + personName = name; + personAge = age; + } +} + diff --git a/CSHARP/bin/Debug/net9.0/CSHARP.dll b/CSHARP/bin/Debug/net9.0/CSHARP.dll index 651f8dc..5a6b5ca 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 4078372..0c47665 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 eff4e44..e593fe4 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 dd4bab4..c4f620d 100644 --- a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs +++ b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs @@ -13,10 +13,10 @@ 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+2101d584f338f6f88ae1a4305d8bd8c1bb8d13cf")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a385581ef2126891ffe561caf708150c6ef0c3cd")] [assembly: System.Reflection.AssemblyProductAttribute("CSHARP")] [assembly: System.Reflection.AssemblyTitleAttribute("CSHARP")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Создано классом WriteCodeFragment MSBuild. +// Generated by the MSBuild WriteCodeFragment class. diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache index 9850935..42986f0 100644 --- a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache +++ b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache @@ -1 +1 @@ -8e1d40d7011353f00b3998c361926632fbcce86fc7b441528c4e189b70a28f7a +e5d3a2d50b713fd5feb66a02c824290572091f66fdfcd5902a5e5cb105d4cb38 diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.dll b/CSHARP/obj/Debug/net9.0/CSHARP.dll index 651f8dc..5a6b5ca 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 eff4e44..e593fe4 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 4078372..0c47665 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 df207d6..010fbbd 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 df207d6..010fbbd 100644 Binary files a/CSHARP/obj/Debug/net9.0/refint/CSHARP.dll and b/CSHARP/obj/Debug/net9.0/refint/CSHARP.dll differ