Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active January 8, 2026 18:01
Show Gist options
  • Select an option

  • Save sunmeat/590ea4f8c3d0816f1c311c6aa13e7a2a to your computer and use it in GitHub Desktop.

Select an option

Save sunmeat/590ea4f8c3d0816f1c311c6aa13e7a2a to your computer and use it in GitHub Desktop.
C# assossiation example
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