Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OsobaKlasa
- {
- public string Imie;
- public int Wiek;
- public OsobaKlasa(string imie, int wiek)
- {
- Imie = imie;
- Wiek = wiek;
- }
- }
- public struct OsobaStruct
- {
- public string Imie;
- public int Wiek;
- public OsobaStruct(string imie, int wiek)
- {
- Imie = imie;
- Wiek = wiek;
- }
- }
- public record OsobaRecord(string Imie, int Wiek);
- public class Program
- {
- private static void Main(string[] args)
- {
- OsobaKlasa osoba3 = new OsobaKlasa("Mariusz", 14);
- //OsobaKlasa osoba2 = new OsobaKlasa("Mariusz", 14);
- OsobaStruct osoba4 = new OsobaStruct("Mariusz", 14);
- //OsobaStruct osoba2 = new OsobaStruct("Mariusz", 14);
- var osoba1 = new OsobaRecord("Mariusz", 14);
- OsobaRecord osoba2 = new("Mariusz", 14);
- System.Console.WriteLine(osoba1.Imie);
- System.Console.WriteLine(osoba1 == osoba2);
- //ZmienImie(osoba2, "Martyna");
- System.Console.WriteLine(osoba1);
- System.Console.WriteLine(osoba3); // klasa
- System.Console.WriteLine(osoba4); // struktura
- }
- private static void ZmienImie(OsobaKlasa osoba, string noweImie)
- {
- osoba.Imie = noweImie;
- }
- private static void ZmienImie(OsobaStruct osoba, string noweImie)
- {
- osoba.Imie = noweImie;
- }
- private static void ZmienImie(OsobaRecord osoba, string noweImie)
- {
- //osoba.Imie = noweImie;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment