Beispiel #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            // assign player name to pName

            string pName = txtName.Text;

            // assign the four text boxes to an array
            // use a loop to process each textbox in the array

            TextBox[] roundBoxes = { txtRound1, txtRound2, txtRound3, txtRound4 };

            // a jagged array is an array of arrays
            // it is an array whose elements are arrays

            // use a jagged array to store the scores of each round as an array
            // create a one-dimensional array with four elements.
            // each of the four elements is also a one-dimensional array

            int[][] roundScores = new int[4][];

            for (int round = 0; round < 4; ++round)
            {
                // split each hole score in the round using tab (\t) as the split character

                string[] tempStrScores = roundBoxes[round].Text.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                // convert the string array to an int and assign to roundScores array

                int[] tempIntScores = Array.ConvertAll(tempStrScores, int.Parse);

                roundScores[round] = tempIntScores;
            }

            // create a two-dimensional array with the data from the jagged array

            int[,] scoresByRound = new int[4, 18];

            for (int row = 0; row < 4; ++row)
            {
                for (int col = 0; col < 18; ++col)
                {
                    scoresByRound[row, col] = roundScores[row][col];
                }
            }

            // instantiate ScoreCard object

            aCard = new ScoreCard(pName, scoresByRound);

            // disable/enable controls

            grpScoreInfo.Enabled = false;
            grpStats.Enabled     = true;
        }