Click here to Skip to main content
15,998,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I get an user input into an array? When I use the ReadLine code it gives an error:
C#
string[] str;
str = new string[10];
Console.WriteLine("enter the string");
str[0] = Console.ReadLine();

Should I use 0 as I have used above?

[Corrected code formatting]
Posted
Updated 18-Sep-22 23:49pm
v2

1 solution

C#
string []answer = new string[10];
for(int i = 0;i<answer.length;i++)
{
        answer[i]= Console.ReadLine();
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900