二维数组问题
利用二维数组制作通讯录,通讯录中保存姓名,电话,qq等信息,通过姓名查找对应的通讯信息。输入需要查找的姓名,输出相应的姓名,电话,qq等。其中,查找过程写在search()方法中,在控制台下完成。
static void Main(string[] args) { //初始数据 string[,] addressBook = new string[,] { { "A,110,QQ" }, { "B,120,qq" } }; //查询 string[] address = Search(addressBook, "A").Split(','); string name = address.Length >= 3 ? address[0] : null; string tell = address.Length >= 3 ? address[1] : null; string qq = address.Length >= 3 ? address[2] : null; } private static string Search(string[,] addressBook, string name) { string str = string.Empty; foreach (string address in addressBook) { str = address.Contains(name) ? address : str; } return str; }