Last active
January 8, 2026 18:01
-
-
Save sunmeat/590ea4f8c3d0816f1c311c6aa13e7a2a to your computer and use it in GitHub Desktop.
C# assossiation example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace AssociationExample | |
| { | |
| public class Person | |
| { | |
| public string? Name { get; set; } // асоціація (поле з типом іншого класу) | |
| public string? Surname { get; set; } | |
| public string SaySomething() // асоціація (повернення значення з типом іншого класу, string) | |
| { | |
| string? local = "всім вже привіт"; // асоціація (локальна змінна з типом іншого класу) | |
| return local; | |
| } | |
| } | |
| public class Cat | |
| { | |
| public string? Nick { get; set; } | |
| public double Weight { get; set; } | |
| public void PlayWith(Person person) // асоціація (параметр типу іншого класу) | |
| { | |
| Console.WriteLine($"кіт {Nick} грається з своїм господарем {person.Name}"); | |
| } | |
| } | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| Console.OutputEncoding = System.Text.Encoding.UTF8; | |
| var c = new Cat(); | |
| c.Nick = "Loki"; | |
| var p = new Person(); | |
| p.Name = "Alex"; | |
| c.PlayWith(p); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment