using System.Collections.Generic;
public class Part : IEquatable<Part>
public string PartName { get; set; }
public int PartId { get; set; }
public override string ToString()
return "ID: " + PartId + " Name: " + PartName;
public override bool Equals(object obj)
if (obj == null) return false;
Part objAsPart = obj as Part;
if (objAsPart == null) return false;
else return Equals(objAsPart);
public override int GetHashCode()
public bool Equals(Part other)
if (other == null) return false;
return (this.PartId.Equals(other.PartId));
public static void Main()
List<Part> parts = new List<Part>();
parts.Add(new Part() {PartName="crank arm", PartId=1234});
parts.Add(new Part() { PartName = "chain ring", PartId = 1334 });
parts.Add(new Part() { PartName = "regular seat", PartId = 1434 });
parts.Add(new Part() { PartName = "banana seat", PartId = 1444 });
parts.Add(new Part() { PartName = "cassette", PartId = 1534 });
parts.Add(new Part() { PartName = "chain ring", PartId = 1634 });
Console.WriteLine(parts.FirstOrDefault(x => x.PartName == "chain ring4" ));