© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
Cam

✅ Help with Simplifying Method further

Anyway to make this code smaller so that i dont have to write "new List<Avalonia.Point>" and "new Avalonia.Point(x,y)" so many times?
Preferably wanting a function where i can parse as many points into the method as i need.
I have already added a method to create the line but it still contains too much rubbish repetitive code

public partial class Newmarket : UserControl
{
    public List<Polyline> newmarketTurnouts = new List<Polyline>();
    public bool normal = true;
    public Newmarket()
    {
        InitializeComponent();
        buildPanel();
        PanelGrid panelGrid = new PanelGrid(NewmarketPanel);
    }

    public void buildPanel() // Build Dynamic Points to Panel
    {
        newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(100, 480), new Avalonia.Point(112, 480) })); // 251B - Down Main
        newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(138, 420), new Avalonia.Point(150, 420) })); // 251A - Up Main
        newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(150, 430), new Avalonia.Point(140, 430), new Avalonia.Point(110, 470), new Avalonia.Point(100, 470) })); // 251 Crossover

        
        NewmarketPanel.Children.Add(newmarketTurnouts);
    }
    public Polyline drawToPanel(List<Avalonia.Point> points) // Create new Polyline
    {
        Polyline newObject = new Polyline
        {
            Stroke = Avalonia.Media.Brushes.Red,
            StrokeThickness = 2
        };
        var n = points.Count;
        for (int i = 0; i < n; i++)
        {
            newObject.Points.Add(points[i]);
        }
        return newObject;
    }
}
public partial class Newmarket : UserControl
{
    public List<Polyline> newmarketTurnouts = new List<Polyline>();
    public bool normal = true;
    public Newmarket()
    {
        InitializeComponent();
        buildPanel();
        PanelGrid panelGrid = new PanelGrid(NewmarketPanel);
    }

    public void buildPanel() // Build Dynamic Points to Panel
    {
        newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(100, 480), new Avalonia.Point(112, 480) })); // 251B - Down Main
        newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(138, 420), new Avalonia.Point(150, 420) })); // 251A - Up Main
        newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(150, 430), new Avalonia.Point(140, 430), new Avalonia.Point(110, 470), new Avalonia.Point(100, 470) })); // 251 Crossover

        
        NewmarketPanel.Children.Add(newmarketTurnouts);
    }
    public Polyline drawToPanel(List<Avalonia.Point> points) // Create new Polyline
    {
        Polyline newObject = new Polyline
        {
            Stroke = Avalonia.Media.Brushes.Red,
            StrokeThickness = 2
        };
        var n = points.Count;
        for (int i = 0; i < n; i++)
        {
            newObject.Points.Add(points[i]);
        }
        return newObject;
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Simplifying Method Parameters: C# 13 vs C# 12
C#CC# / help
15mo ago
❔ Help with C# TSP recursive method
C#CC# / help
3y ago
✅ Method calling help
C#CC# / help
3y ago
✅ [SOLVED] Need help with converting async method to a 'normal' method
C#CC# / help
3y ago