Click here to Skip to main content
12,070,248 members (28,946 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Multidimensional
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;
Posted 4-Nov-12 11:05am
PaulN18103
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

(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");
    }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Could you please explain a bit about that part which prints the code and removing the code?
I am struggling on them.
  Permalink  
Comments
PaulN18 8-Nov-12 18:23pm
   
You're studying computer science at Anglia Ruskin, aren't you?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

no worries, I sorted the matter out.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100