Klasa i obiekty w C#
Tworzenie klasy z polami i metodami
class Product
{
private string _name;
public Product(string name)
{
_name = name;
}
public string GetName()
{
return _name;
}
public void SetName(string name)
{
_name = name;
}
}
Tworzenie klasy z właściwościami i metodami
class Product
{
public string Name { get; private set; }
public Product(string name = "Default")
{
Name = name;
}
public void SetName(string name)
{
Name = name;
}
}
Product product = new("TV");
product.SetName("New TV");
Product product2 = new();
lblInfo.Content = product2.Name;