在C#中将用户数据存储在多维数组中 [英] Storing users data in a Multidimensional Array in C#
本文介绍了在C#中将用户数据存储在多维数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个控制台应用程序,将用户名和电话号码存储在多维数组中,此刻,我不知道如何使程序读取用户输入的信息并将其存储在数组中.
到目前为止我有什么
I need to create a console application that stores a users name and phone number in a multidimensional array, at the moment I do not know how to get the program to read the information that the users has entered and store it in an array.
What I have so far
using System;
public class Phonebook
{
public static void Main()
{
String inputname, inputPhoneNo, userselection;
String[,] name = new string[20,20];
Console.WriteLine("Please select and option" +
Environment.NewLine + "1. Add Entry" +
Environment.NewLine + "2. Delete Entry" +
Environment.NewLine + "3. Print Book to Screen" +
Environment.NewLine + "4. Continue 'Y' or 'N'");
userselection = Console.ReadLine();
switch (userselection)
{
case "1":
string [] = Console.ReadLine();
break;
推荐答案
(如果我明白了),您需要这样的东西:
(If I got you) You need something like this:
public static void Main()
{
String inputname, inputphoneno, userselection;
String[,] addrbook = new string[20, 2];
int n = 0;
do
{
Console.WriteLine("Please select and option" +
Environment.NewLine + "1. Add Entry" +
Environment.NewLine + "2. Delete Entry" +
Environment.NewLine + "3. Print Book to Screen" +
Environment.NewLine + "4. Quit");
userselection = Console.ReadLine();
switch (userselection)
{
case "1":
Console.WriteLine("Name:");
addrbook[n,0] = Console.ReadLine();
Console.WriteLine("Phone No.:");
addrbook[n,1] = Console.ReadLine();
break;
case "2":
// code for entry removal
break;
case "3":
// code for printing the address book
break;
case "4":
break;
}
n++;
} while (userselection != "4");
}
您能否解释一下有关打印代码并删除代码的部分?
我正在努力.
Could you please explain a bit about that part which prints the code and removing the code?
I am struggling on them.
不用担心,我已经解决了这个问题.
no worries, I sorted the matter out.
这篇关于在C#中将用户数据存储在多维数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文