У меня есть это домашнее задание, у меня есть только одна проблема, и я не знаю решения.У нас есть этот класс, и мы не должны создавать другие переменные или методы ...
У меня есть beers словарь с .Но у метода есть только имя объекта Beer (prop), а не объект.
И у меня нет другой идеи, как я могу получить имя объекта Beer из словаря
У меня есть только 2 идеи, но они не работают.
Во-первых, я попытался использовать метод ContainsKey ().Вторая итерация foreach
using System;
using System.Collections.Generic;
namespace PubBeer
{
public class Beer
{
string name;
int price;
double alcohol;
public string Name{ get { return name; } }
public int Price{ get; set; }
public double Alcohol{ get { return alcohol;} }
public Sör(string name, int price, double alcohol)
{
this.name= name;
this.price= price;
this.alcohol= alcohol;
}
public override bool Equals(object obj)
{
if (obj is Beer)
{
Beer other = (Beer)obj;
return this.name== other.name;
}
return false;
}
}
public class Pub
{
int income;
IDictionary<Beer, int> beers= new Dictionary<Beer, int>();
public int Income{ get; set; }
public int Sold(string beerName, int mug)
{
// Here the problem
beers; // Here I want to like this: beers.Contains(beerName)
// beers.ContainsKey(Object.Name==beerName) or someone like this
// foreach (var item in beers)
// {
// item.Key.Name== beerName;
// }
}
...