Помогите реализовать деструктор – не пойму, как сослаться на него:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Laba6
{
class EngMoney
{
private float funt, pens, shilling,funt1,pens1,shilling1,nomer;
private bool vuvod;
public EngMoney(float funt, float pens, float shilling, float funt1, float pens1, float
shilling1, int nomer)
{
if (nomer == 1)
{
this.funt = funt + funt1;
this.pens = pens + pens1;
this.shilling = shilling+shilling1;
}
if (nomer == 2)
{
this.funt = funt - funt1;
this.pens = pens - pens1;
this.shilling = shilling - shilling1;
}
if (nomer == 3)
{
this.funt = funt * funt1;
this.pens = pens * pens1;
this.shilling = shilling * shilling1;
}
if (nomer == 4)
{
this.funt = funt / funt1;
this.pens = pens / pens1;
this.shilling = shilling / shilling1;
}
if (nomer == 5)
{
shilling = funt * 12 * 20;
shilling1 = funt1 * 12 * 20;
if (shilling > shilling1)
{
vuvod = false;
}
if (shilling < shilling1)
{
vuvod = true;
}
}
this.funt1 = funt1;
this.pens1 = pens1;
this.shilling1 = shilling1;
this.nomer = nomer;
}
public void Print()
{
if (nomer == 5)
{
if (vuvod == false)
{
Console.WriteLine("Первая сумма больше");
}
if (vuvod == true)
{
Console.WriteLine("Вторая сумма больше первой");
}
EngMoney();
}
else
{
Console.WriteLine("funt: " + funt);
Console.WriteLine("pens :" + pens);
Console.WriteLine("shilling: " + shilling);
}
}
~EngMoney()
{
Console.Beep();
Console.WriteLine("Disposed");
}
}
class Program
{
public static float f, p, s,f1,p1,s1;
public static int nomer;
static void Main(string[] args)
{
Console.WriteLine("Ввод первой суммы");
Console.WriteLine("Введите фунты: ");
f = float.Parse(Console.ReadLine());
Console.WriteLine("Введите пенсы: ");
p = float.Parse(Console.ReadLine());
Console.WriteLine("Введите шилинги: ");
s = float.Parse(Console.ReadLine());
Console.WriteLine("Ввод второй суммы");
Console.WriteLine("Введите фунты: ");
f1 = float.Parse(Console.ReadLine());
Console.WriteLine("Введите пенсы: ");
p1 = float.Parse(Console.ReadLine());
Console.WriteLine("Введите шилинги: ");
s1 = float.Parse(Console.ReadLine());
Console.WriteLine("Выберите действие:");
Console.WriteLine("1. Сложение");
Console.WriteLine("2. Вычитание");
Console.WriteLine("3. Умножение");
Console.WriteLine("4. Деление");
Console.WriteLine("5. Сравнение");
nomer = int.Parse(Console.ReadLine());
EngMoney newValue = new EngMoney(f, p, s, f1, p1, s1,nomer);
newValue.Print();
Console.ReadLine();
}
}
}
IDisposableинтерфейс. – aepot Jun 09 '20 at 09:34IDisposableклассы. Память почистит GC автоматически, как только ссылка на объект будет забыта, но не сразу, а только когда сам соизволит это сделать. Там много внутри всяких оптимизаций, нацеленных на то, чтобы не подтормаживать ваше приложение при сборке мусора. – aepot Jun 09 '20 at 10:23GC.Collect()надо обнулить все ссылки на объект, иначе он не будет собран. – aepot Jun 09 '20 at 11:53