用户在控制台应用程序中的数组中输入? [英] user input in a array in console application??

查看:122
本文介绍了用户在控制台应用程序中的数组中输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取用户输入的数组?当我使用ReadLine代码时,出现错误:

How can I get an user input into an array? When I use the ReadLine code it gives an error:

string[] str;
str = new string[10];
Console.WriteLine("enter the string");
str[0] = Console.ReadLine();


我应该像上面一样使用0吗?

[正确的代码格式]


Should I use 0 as I have used above?

[Corrected code formatting]

推荐答案

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


这篇关于用户在控制台应用程序中的数组中输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆