如何一起添加数字? [英] How do I keep adding numbers together?

查看:87
本文介绍了如何一起添加数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想制作一个小型高尔夫记分卡。我得到了我需要的数字,但它们都是彼此分开的。如何让我们成为一个大堆,好像我的第一个得分是+2,当下一个是-1然后它会告诉我+1。



希望它有任何意义。



这是代码

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

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

推荐答案

创建一个简单的POCO类(或结构)来存储每个洞的信息。



class ScoreForHole

{

public int Par {get; set;}

public int Shots {get; set;}

}



回发后解析传入的数据,创建一个新的POCO实例,并将其添加到一个集合中。



使用 LinkedList< T> [ ^ ]如果您在每轮比赛结束后立即捕捉 (1 - > 2 - > 3)。



但是如果每个洞的分数可以随时输入,那么使用< a href =https://msdn.microsoft.com/en-us/library/ms132319(v=vs.11 0).aspx> SortedList< TKey,TValue> [ ^ ]会更合适。关键值是孔#,存储的值将是POCO。



使用存储在任一集合中的数据,您可以从开始迭代列表完成,并在游戏的任何特定阶段结束时重建得分!
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!


这篇关于如何一起添加数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆