C# Draw multiple Lines

I would make a Line class having start and end point of the line in struct Point and make list of that class instead of having four arrays.

public class MyLine
{
     public Point StartPoint {get; set;}
     public Point EndPoint {get; set;}

     public void DrawLine()
     {
         //Draw line code goes here
     }
}

Now you have line class with required field and method to draw line. You drawLines method that might be in some other class will create list of MyLine class and can draw that list of Lines using Line class method DrawLine

private void DrawLines()
{
    List<MyLine> listMyLines = new  List<MyLine>();
    listMyLines.Add(new MyLine{StartPoint = new Point(0, 100), EndPoint = new Point(334, 100)});       

    for (int i = 0; i < listMyLines.Count; i++)
    {
         listMyLines[i].DrawLine();
    }
}
原文地址:https://www.cnblogs.com/zeroone/p/9732195.html