First, I initialize an ArrayList to my code then add each input by the user. I manage to add a data and show but after doing so it throws an exception of OutOfRange and I don't see any reason why.
I already asked about something like this but it was to check the array has value stored yet Link to my first question. But the problem I encountered now is something this exception
static ArrayList fName = new ArrayList();
static ArrayList cNumber = new ArrayList();
public static void createContact()
{
Console.Write("\nEnter your full name: ");
fullName = Console.ReadLine();
fName.Add(fullName);
Console.Write("\nEnter your contact number: ");
contactNumber = Console.ReadLine();
cNumber.Add(contactNumber);
}
public static void displayContact()
{
if (fName.Count == 0 && cNumber.Count == 0)
{
Console.WriteLine("No Data Yet!");
}
else if (fName.Count > 0 && cNumber.Count > 0)
{
for (int j = 0; j < numbers.Length; j++)
{
Console.WriteLine(numbers[j] + ". " + fName[j] + " - " + cNumber[j]);
}
}
else if (fName.Count <= 10 && cNumber.Count <= 10)
{
Console.WriteLine("Maximum data acquired! Terminating program...");
}
}
The output goes something like this: