using System;
public class Empleado
{
string primerNombre;
public string PrimerNombre
{
get
{
return primerNombre;
}
set
{
primerNombre = value;
}
}
string apellido;
public string Apellido
{
get
{
return apellido;
}
set
{
apellido = value;
}
}
int edad;
public int Edad
{
get
{
return edad;
}
set
{
edad = value;
}
}
int idEmpleado;
public int IdEmpleado
{
get
{
return idEmpleado;
}
set
{
idEmpleado = value;
}
}
// Sobreescritura del método ToString
public override string ToString()
{
return String.Format("Nombre: {0}, Apellido: {1}, y Edad: {2}.", primerNombre, apellido, edad);
}
// Sobreescritura del me´todo Equals
public override bool Equals(object obj)
{
if (obj != null && obj is Empleado)
{
Empleado emp = (Empleado) obj;
if (emp.primerNombre == this.primerNombre &&
emp.apellido == this.apellido &&
emp.edad == this.edad &&
emp.idEmpleado == this.idEmpleado )
{
return true;
}
}
return false;
}
}
public class EmpleadoPrueba
{
public static void Main()
{
Empleado emp1 = new Empleado();
emp1.PrimerNombre = "Juan";
emp1.Apellido = "Ortiz";
emp1.Edad = 40;
emp1.IdEmpleado = 123456789;
Empleado emp2 = new Empleado();
emp2.PrimerNombre = "Juan";
emp2.Apellido = "Ortiz";
emp2.Edad = 40;
emp2.IdEmpleado = 123456789;
// Comparación de dos instancias de Epleado diferentes.
Console.WriteLine ("Hash de emp1: {0}", emp1.GetHashCode());
Console.WriteLine ("Hash de emp2: {0}", emp2.GetHashCode());
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIEVtcGxlYWRvCnsKICAgIHN0cmluZyBwcmltZXJOb21icmU7CiAgICBwdWJsaWMgc3RyaW5nIFByaW1lck5vbWJyZQogICAgewogICAgICAgIGdldAogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIHByaW1lck5vbWJyZTsKICAgICAgICB9CiAgICAgICAgc2V0CiAgICAgICAgewogICAgICAgICAgICBwcmltZXJOb21icmUgPSB2YWx1ZTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHN0cmluZyBhcGVsbGlkbzsKICAgIHB1YmxpYyBzdHJpbmcgQXBlbGxpZG8KICAgIHsKICAgICAgICBnZXQKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBhcGVsbGlkbzsKICAgICAgICB9CiAgICAgICAgc2V0CiAgICAgICAgewogICAgICAgICAgICBhcGVsbGlkbyA9IHZhbHVlOwogICAgICAgIH0KICAgIH0KICAgIAogICAgaW50IGVkYWQ7CiAgICBwdWJsaWMgaW50IEVkYWQKICAgIHsKICAgICAgICBnZXQKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBlZGFkOwogICAgICAgIH0KICAgICAgICBzZXQKICAgICAgICB7CiAgICAgICAgICAgIGVkYWQgPSB2YWx1ZTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIGludCBpZEVtcGxlYWRvOwogICAgcHVibGljIGludCBJZEVtcGxlYWRvCiAgICB7CiAgICAgICAgZ2V0CiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gaWRFbXBsZWFkbzsKICAgICAgICB9CiAgICAgICAgc2V0CiAgICAgICAgewogICAgICAgICAgICBpZEVtcGxlYWRvID0gdmFsdWU7CiAgICAgICAgfQogICAgfQogICAgCiAgICAvLyBTb2JyZWVzY3JpdHVyYSBkZWwgbcOpdG9kbyBUb1N0cmluZwogICAgcHVibGljIG92ZXJyaWRlIHN0cmluZyBUb1N0cmluZygpCiAgICB7CiAgICAgICAgcmV0dXJuIFN0cmluZy5Gb3JtYXQoIk5vbWJyZTogezB9LCBBcGVsbGlkbzogezF9LCB5IEVkYWQ6IHsyfS4iLCBwcmltZXJOb21icmUsIGFwZWxsaWRvLCBlZGFkKTsKICAgIH0KICAgIAogICAgLy8gU29icmVlc2NyaXR1cmEgZGVsIG1lwrR0b2RvIEVxdWFscwogICAgcHVibGljIG92ZXJyaWRlIGJvb2wgRXF1YWxzKG9iamVjdCBvYmopCiAgICB7CiAgICAgICAgaWYgKG9iaiAhPSBudWxsICYmIG9iaiBpcyBFbXBsZWFkbykKICAgICAgICB7CiAgICAgICAgICAgIEVtcGxlYWRvIGVtcCA9IChFbXBsZWFkbykgb2JqOwogICAgICAgICAgICAKICAgICAgICAgICAgaWYgKGVtcC5wcmltZXJOb21icmUgPT0gdGhpcy5wcmltZXJOb21icmUgJiYKICAgICAgICAgICAgICAgIGVtcC5hcGVsbGlkbyA9PSB0aGlzLmFwZWxsaWRvICYmIAogICAgICAgICAgICAgICAgZW1wLmVkYWQgPT0gdGhpcy5lZGFkICYmIAogICAgICAgICAgICAgICAgZW1wLmlkRW1wbGVhZG8gPT0gdGhpcy5pZEVtcGxlYWRvICkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQp9CgpwdWJsaWMgY2xhc3MgRW1wbGVhZG9QcnVlYmEKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewogICAgICAgIEVtcGxlYWRvIGVtcDEgPSBuZXcgRW1wbGVhZG8oKTsKICAgICAgICBlbXAxLlByaW1lck5vbWJyZSA9ICJKdWFuIjsKICAgICAgICBlbXAxLkFwZWxsaWRvID0gIk9ydGl6IjsKICAgICAgICBlbXAxLkVkYWQgPSA0MDsKICAgICAgICBlbXAxLklkRW1wbGVhZG8gPSAxMjM0NTY3ODk7CiAgICAgICAgCiAgICAgICAgRW1wbGVhZG8gZW1wMiA9IG5ldyBFbXBsZWFkbygpOwogICAgICAgIGVtcDIuUHJpbWVyTm9tYnJlID0gIkp1YW4iOwogICAgICAgIGVtcDIuQXBlbGxpZG8gPSAiT3J0aXoiOwogICAgICAgIGVtcDIuRWRhZCA9IDQwOwogICAgICAgIGVtcDIuSWRFbXBsZWFkbyA9IDEyMzQ1Njc4OTsKICAgICAgICAKICAgICAgICAvLyBDb21wYXJhY2nDs24gZGUgZG9zIGluc3RhbmNpYXMgZGUgRXBsZWFkbyBkaWZlcmVudGVzLgogICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiSGFzaCBkZSBlbXAxOiB7MH0iLCBlbXAxLkdldEhhc2hDb2RlKCkpOwogICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiSGFzaCBkZSBlbXAyOiB7MH0iLCBlbXAyLkdldEhhc2hDb2RlKCkpOwoJfQp9