特定のコードを探しているわけではなく、情報とガイダンスを探しています。私は学びたいが、誰かがそれをコード化しないようにしたい。あるメソッドから2つの配列を渡して別のメソッドからユーザー情報を収集するC#
2つの配列を別々のメソッドに渡してユーザー入力を満たす方法を探しています。私はこれを理解することができないと私はテキストと講義だけでなく、様々なサイトを研究し、これを行うために必要な技術を見つけることができません。私は、1つの配列を別のメソッド(IEのavg/sumなど)に渡す方法を知っていますが、1つの別のメソッドから2つの配列を埋める方法はありません。どんな指導や情報も高く評価されます。これは私が今までに持っているもの、あるいはむしろ私が残したものです。私は他の方法をかなり完成させました。デバッグ段階に移行するには、この部分が必要です。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PhoneDial
{
class Program
{
// Get player names and their scores and stores them into array for an unknown number of players up to 100
static void InputData(string[] nameList, int[]playerScore)
{
string userInput;
int count = 0;
do
{
Console.Write("\nEnter a players name: ");
userInput = Console.ReadLine();
if (userInput != "Q" && userInput != "q")
{
nameList[0] = Console.ReadLine();
++count;
}
else break;
Console.WriteLine("Enter {0}'s score:", userInput);
playerScore[0] = Convert.ToInt32(Console.ReadLine());
} while (userInput != "Q" && userInput != "q");
}
//Declare variables for number of players and average score and two arrays of size 100 (one for names, one for respective scores
//Calls functions in sequence, passing necessary parameters by reference
//InputData(), passing arrays and number of players variable by reference
//DisplayPlayerData(), passing arrays and number of players by reference
//CalculateAverageScore(), passing arrays and number of players by reference. Store returned value in avg variable
//DisplayBelowAverage(), passing arrays and number of players variable by reference, passing average variable by value
static void Main(string[] args)
{
string[] nameList = new string[100];
int[] playerScore = new int[100];
int count = 0, avg = 0;
InputData(nameList, playerScore);
}
2つの配列を保持するクラスを作成する方法はありますか?次に、あなたの好きなところでこれを渡すことができます... –
'static void InputData(ref string name、ref int score)' static void InputData(string [] name、int [] score、ref int numberOfPlayers) ' –
クラスを作成するとmain()からそれを削除しますか? – user1174357