Click here to Skip to main content
15,887,410 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
So I wanted to make a small golf scorecard. I get the numbers I need but they are all separeated form eachother. How can I make them into a "big pile" as if my first score was +2 and when next is -1 then it will show me +1.

Hope it makes any sence.

Here is the code
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(tPar.Text);
            int b = Convert.ToInt32(tShotsMade.Text);
            int c = b - a;
            ttotalscore.Text += "score: " +(c.ToString()) + Environment.NewLine;
        }
    }
}
Posted
Comments
[no name] 27-Jul-15 18:54pm    
First, stop using Convert. Use int.TryParse instead. Then.... what?
PIEBALDconsult 27-Jul-15 18:57pm    
+5

1 solution

Create a simple POCO class (or struct) to store information on each hole played.

class ScoreForHole
{
public int Par {get;set;}
public int Shots {get;set;}
}

Upon postback parse the incoming data, create a new instance of the POCO, and add it to some a collection.

Using a LinkedList<T>[^] is appropriate if you are capturing details immediately after play has finished for each round (1 -> 2 -> 3).

But if the scores for each hole played can be entered at any time, then using SortedList<TKey,TValue>[^] would be more appropriate. The key value would be the hole #, and the value stored would be the POCO.

Using data stored in either collection, you can iterate through the list from start to finish, and 'reconstruct' the score at the end of any particular stage of the game!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900