Первый:
Код: Выделить всё
namespace Dinero
{
class Dollar
{
#region Atributos
public Double cant;
#endregion
#region Constructores
public Dollar()
{
this.cant = 0;
}
public Dollar(Double amount)
{
this.cant = amount;
}
#endregion
#region Sobrecarga de Operadores
public static Dollar operator +(Euro eu, Dollar dol)
{
Dollar devolucion = new Dollar();
devolucion.cant = eu.cant + (dol.cant * 1.3642);
return devolucion;
}
public static Dollar operator -(Euro eu, Dollar dol)
{
Dollar devolucion = new Dollar();
devolucion.cant = eu.cant + (dol.cant * 1.3642);
return devolucion;
}
public static bool operator ==(Euro eu, Dollar dol)
{
if (eu.cant == (dol.cant * 1.3642))
return true;
else
return false;
}
public static bool operator !=(Euro eu, Dollar dol)
{
if (eu.cant != (dol.cant * 1.3642))
return true;
else
return false;
}
#endregion
}
}
Код: Выделить всё
namespace Dinero
{
class Euro
{
#region Atributos
public Double cant;
#endregion
#region Constructores
public Euro()
{
this.cant = 0;
}
public Euro(Double amount)
{
this.cant = amount;
}
#endregion
#region Sobrecarga de operadores
public static Euro operator +(Euro eu, Dollar dol)
{
Euro devolucion = new Euro();
devolucion.cant = eu.cant + (dol.cant * 1.3642);
return devolucion;
}
public static Euro operator -(Euro eu, Dollar dol)
{
Euro devolucion = new Euro();
devolucion.cant = eu.cant - (dol.cant * 1.3642);
return devolucion;
}
public static bool operator ==(Euro eu, Dollar dol)
{
if (eu.cant == (dol.cant * 1.3642))
return true;
else
return false;
}
public static bool operator !=(Euro eu, Dollar dol)
{
if (eu.cant != (dol.cant * 1.3642))
return true;
else
return false;
}
#endregion
}
}
Код: Выделить всё
namespace Ejercicio_21
{
class Ejercicio_21
{
static void Main(string[] args)
{
Console.Title = "Ejercicio Nro 21";
Euro euro00 = new Euro(1);
Dollar dollar00 = new Dollar(1);
Euro sumaEuros = euro00 + dollar00;
Ошибка 11. Вызов неоднозначен между следующими методами илисвойства: «Динеро.Евро.оператор +(Динеро.Евро, Динеро.Доллар)» и
»Динеро.Доллар.оператор +(Динеро.Евро, Динеро.Доллар)»
Я предполагаю, что это как-то связано с разными пространствами имен, но я не смог понять этого, даже используя Google.
Это — это первый вопрос, который я задаю здесь, поэтому, пожалуйста, не сжигайте меня до забвения и извините за мой ужасный английский.
Примечание: я вынужден держать занятия по доллару и евро в другое пространство имен, чем основная программа.
Подробнее здесь: https://stackoverflow.com/questions/781 ... properties