ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C# List
    Search: C#(Csharp) C#(Csharp) 2023. 2. 15. 14:54

     

    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 })

     

    'C#(Csharp)' 카테고리의 다른 글

    C# get set property  (0) 2023.02.15
    SortedList  (0) 2021.08.08
    Struct and Class  (0) 2021.07.31
    실수형 소수점 자리 제한하여 출력(float, decimal)  (0) 2021.07.27
    Formating strings  (0) 2021.07.27
    List.Sort  (0) 2021.07.26
    SortedSet  (0) 2021.07.24
    HashSet  (0) 2021.07.24

    댓글