Sin descripción

ababin 3a5571dfe7 Добавить 'README.md' hace 5 meses
bin 957c1092e9 lab hace 5 meses
obj 957c1092e9 lab hace 5 meses
ConsoleApp3.csproj 957c1092e9 lab hace 5 meses
ConsoleApp3.sln 957c1092e9 lab hace 5 meses
Program.cs 957c1092e9 lab hace 5 meses
README.md 3a5571dfe7 Добавить 'README.md' hace 5 meses

README.md

Библиотеки классов

namespace ClassLibrary1
{
    public class Instrument
    {
        public string name { get; set; }
        public int price { get; set; }
    }
}
using ClassLibrary1;

var guitar = new Instrument
{
    name = "gibson",
    price = 2000
};

Console.WriteLine(guitar.name);

Вывод: gibson

Получение типа через typeof:

Type myType = typeof(Guitar);

Console.WriteLine(myType.ToString());
Console.ReadLine();

public class Guitar
{
    public string Name { get; set; }
    public int Gstrings { get; set; }

    public Guitar(string n, int a)
    {
        Name = n;
        Gstrings = a;
    }
    public void Display()
    {
        Console.WriteLine($"Название: {Name}  Количество струн: {Gstrings}");
    }
    public decimal Payment(int quantity, decimal price)
    {
        return quantity * price;
    }
}

Позднее связывание

class Instrument
{
    public string Name { get; set; }
    public string Brand { get; set; }
    public decimal Price { get; set; }
}

class Guitar : Instrument
{
    public int StringsNumber { get; set; }
    public string BodyMaterial { get; set; }
}

class MusicStore
{
    public List<Instrument> Instruments { get; set; }

    public MusicStore()
    {
        Instruments = new List<Instrument>();
    }

    public void AddInstrument(Instrument instrument)
    {
        Instruments.Add(instrument);
    }

    public static decimal GetPriceWithInterest(Guitar guitar, int percent, int years)
    {
        for (int i = 0; i < years; i++)
        {
            guitar.Price += guitar.Price / 100 * percent;
        }
        return guitar.Price;
    }
}

class Program
{
    static void Main(string[] args)
    {
        var guitar = new Guitar { Name = "Stratocaster", Brand = "Fender", Price = 1000, StringsNumber = 6, BodyMaterial = "Alder" };
        var store = new MusicStore();
        store.AddInstrument(guitar);

        var priceWithInterest = MusicStore.GetPriceWithInterest(guitar, 6, 100);

        Console.WriteLine($"Цена гитары с процентами составляет: {priceWithInterest:C}");
        Console.ReadLine();
    }
}