List<int> list1 = new List<int>();
list.Add(11);
list.Add(22);
list.Add(33);
foreach (int it in list1)
{
Console.WriteLine(it);
}
for (int i = 0; i < list1.Count; i++)
{
Console.WriteLine(list1[i]);
}
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()
{
return PartId;
}
public bool Equals(Part other)
{
if (other == null) return false;
return (this.PartId.Equals(other.PartId));
}
// Should also override == and != operators.
}
// Create a list of parts.
List<Part> parts = new List<Part>();
// Add parts to the list.
parts.Add(new Part() { PartName = "crank arm", PartId = 111 });
parts.Add(new Part() { PartName = "chain ring", PartId = 222 });
parts.Add(new Part() { PartName = "regular seat3", PartId = 333 })