-2
コンパイルすると、配列の情報は表示されません。名前、電話番号、住所は表示されません。空白になるだけです。私はforループを使っていろいろな例を追ってきました。私はそれをうまく動作させることができず、エラーメッセージもありません。 私は誰の入力を感謝します。C#を使用して、名前を持つ文字列配列を使用してforループを使用して2D配列をループしようとしています。コンパイル時に情報が表示されない
string[,] customers = { { "Jay" , "123 Fake Street" , "212 111 1111"},
{" Pete" , "123 Fake Rd", "212 222 2222" },
{ "Will" , "112 Fake Av" , "212 333 3333"}, };
string cusName,
cusInfo;
bool phoneNumberFound = true;
Write("Enter your phone #:")
cusInfo = Convert.ToString(ReadLine());
for (int row = 0; row < customers.GetLength(0); ++row)
{
// Retreving the customers info from the array (second dimension of rows' width)
for (int col = 0; col < customers.GetLength(1); ++col)
{
if (phoneNumberFound)
{
cusInfo = customers[col, 0];
WriteLine();
WriteLine("Customer Name:\t", customers[row, col]);
WriteLine("Address:\t", customers[row, col]);
WriteLine("Phone Number:\t", customers[row, col]);
WriteLine();
//WriteLine("{0} , what size pizza do you want?:");
ReadLine();
}
else
{
WriteLine("Your phone number was not found , please enter your name:\t");
cusName = Convert.ToString(ReadLine());
}
}
}
ことの一つは、あなたが 'cusInfo = Convert.ToString(ReadLineメソッド())と' cusInfo'に顧客の入力を読んでいるということです; '、その後' cusInfoは、[顧客を=とそれをつかいますcol、0];そして、とにかくそれを使うことはありません。 – jdgregson
'customers [col、0]'はcolを最初のランクとして使用しますが、これは他の用途と矛盾します。これは、cusInfoが使用されていないため問題ありません。 WriteLineステートメントが文字列内で指定された引数を使用していないため、空白の出力が得られる理由があります。あなたは、WriteLine( "Customer Name:\ t {0}"、customers [row、col]) 'または' WriteLine( "Customer Name:\ t" + customers [row、col])のいずれかを意味します。 –
あなたは何をしたいですか?達成? 2D配列から詳細を印刷するだけです。質問を投稿する前にチュートリアルをチェックする場合は、 –