Reputation: 935
I am told to design a phonebook which will use 2D array to store Name and Phone numbers in type : string . It should have the functions like add, remove, print methods.
I am yet struggling in this array. I do not know how to fill the whole of array members with "none" whenever a record for name is not present and "000" for its number.
by default, i need it to have this printed: (20 records of none 000) none 000 none 000 none 000 ... none 000 none 000 none 000
I came up with:
string[,] db = new db[20,2];
I am not sure though if its the right, but I just want a 2D array which has 20 rows and 2 columns.
Then I wanna use for or foreach loop to fill the elements by none and 000:
for (int i=0; i<db.Length/2; i++)
for (int j=0; j<db.Length/20; j++)
Could you help me with filling that? Thanks
Upvotes: 1
Views: 1771
Reputation: 133995
The loop you're looking for to initialize the array would be:
for (int i = 0; i < 20; ++i)
{
db[i,0] = "none";
db[i,1] = "000";
}
Upvotes: 0
Reputation: 16651
class Address {
public string Name {get; set; }
public string Phone {get; set; }
}
List<Address> addressBook = new List<Address>();
// Do stuff with your list
No need to use an array.
Upvotes: 4