public override bool Equals(object obj) //EL OBJECT OBJ ES CON EL CUAL SE COMPARA { if (obj == null) //si el objeto recibio es nullo, tira falso { return(false); } if (!(obj is Repuesto)) //si el obj no es repuesto, tira false { return(false); } Repuesto repuestoExterno = (Repuesto)obj; //forma 2 mas facil return(this._codigo == repuestoExterno._codigo); //si son iguales da true y si son diferentes, false //FORMA 1 //if(this._codigo == repuestoExterno.Codigo) //{ // return true; //son iguales //} //else //{ // return false; //no son iguales //} }
//metodos public void AgregarRepuesto(Repuesto r1) { foreach (Repuesto r in _listaRepuestos) { if (r.Equals(r1)) //si meto un codigo de repuesto que ya existe tira esto { throw new RepuestoExistenteException("Repuesto existente."); } } if (r1.CategoriaRep == null) { throw new CategoriaInexistenteException("Error. Se introdujo un codigo de categoria que no existe en la base de datos."); } this._listaRepuestos.Add(r1); }