private float CalcularInteresGanado(Prestamo.TipoDePrestamo tipoPrestamo) { float interesDolar = 0, interesPesos = 0; if (tipoPrestamo == Prestamo.TipoDePrestamo.Dolares) { return(interesDolar += ListaDePrestamo.Where(x => x is PrestamoDolar).Sum(x => ((PrestamoDolar)x).Interes)); } else if (tipoPrestamo == Prestamo.TipoDePrestamo.Pesos) { return(interesPesos += ListaDePrestamo.Where(x => x is PrestamoPesos).Sum(x => ((PrestamoPesos)x).Interes)); } else { interesDolar += ListaDePrestamo.Where(x => x is PrestamoDolar).Sum(x => ((PrestamoDolar)x).Interes); interesPesos += ListaDePrestamo.Where(x => x is PrestamoPesos).Sum(x => ((PrestamoPesos)x).Interes); return(interesDolar + interesPesos); } }
private float CalcularInteresGanado(Prestamo.TipoDePrestamo tipoDePrestamo) { float retorno = 0; float retornoDolar = 0; float retornoPeso = 0; PrestamoDolar prestamoDolar; PrestamoPesos prestamosPesos; foreach (Prestamo item in this.listaDePrestamos) { if (item is PrestamoDolar) { prestamoDolar = (PrestamoDolar)item; retornoDolar += prestamoDolar.Interes; } else { prestamosPesos = (PrestamoPesos)item; retornoPeso += prestamosPesos.Interes; } } switch (tipoDePrestamo) { case Prestamo.TipoDePrestamo.Pesos: retorno = retornoPeso; break; case Prestamo.TipoDePrestamo.Dolares: retorno = retornoDolar; break; case Prestamo.TipoDePrestamo.Todos: retorno = retornoDolar + retornoPeso; break; } return(retorno); }