console.Readline 与console.ReadKey有啥区别?

Lovestudy721 2010-08-06 04:05:50
string[] friendName ={ "joey", "tom", "robert" };
int i;
for (i = 0; i < friendName.Length; i++)
{
Console.WriteLine(friendName[i]);
}
//Console.ReadKey();
Console.ReadLine();

console.Readline 与console.ReadKey有区别吗?
...全文
456 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Thr21ough 2010-08-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyazhe 的回复:]
英文本身已经很直白了。
ReadLine是读一行,怎么确定一行呢?当你输入回车换行,则此函数返回。
ReadKey读一个字符,按任意键则返回。
[/Quote]
+1
allen3010 2010-08-07
  • 打赏
  • 举报
回复
原来如此
pc_242 2010-08-06
  • 打赏
  • 举报
回复
xuexi.....
东莞寻香苑 2010-08-06
  • 打赏
  • 举报
回复
呵呵
前后两者的最后一个单词不一样
windxx 2010-08-06
  • 打赏
  • 举报
回复
原来是...这样啊...
Peter200694013 2010-08-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
COnsole.Read()方法用于获得用户输入任何值的首字符的ASCII值
COnsole.ReadLine()方法用于将获得的数据保存在字符串变量中

Console.ReadKey(); 则是等待用户按下任意键
[/Quote]
+1


//I'm late
xiaoyi_nuo 2010-08-06
  • 打赏
  • 举报
回复
哥们,你这问题问得………… 顶了!
BoyceLyu 2010-08-06
  • 打赏
  • 举报
回复
恩恩 很详细了
兔子-顾问 2010-08-06
  • 打赏
  • 举报
回复
英文本身已经很直白了。
ReadLine是读一行,怎么确定一行呢?当你输入回车换行,则此函数返回。
ReadKey读一个字符,按任意键则返回。
yilvchaxiang 2010-08-06
  • 打赏
  • 举报
回复
顶2楼
wuyq11 2010-08-06
  • 打赏
  • 举报
回复
COnsole.Read()方法用于获得用户输入任何值的首字符的ASCII值
COnsole.ReadLine()方法用于将获得的数据保存在字符串变量中

Console.ReadKey(); 则是等待用户按下任意键
  • 打赏
  • 举报
回复
Console.ReadLine(); 会等待直到用户按下回车,一次读入一行
Console.ReadKey(); 则是等待用户按下任意键,一次读入一个字符。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sys005_date { enum Week:sbyte { 周一=1,周二=2,周三=3,周四=4,周五=5,周六=6,周日=7 } class Program { static void Main(string[] args) { int[] month = new int[13] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Console.WriteLine("请输入今年是第几年?"); int year = Convert.ToInt32(Console.ReadLine()); //考虑闰年 if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) month[2] += 1; Console.WriteLine("请输入查询的日期是该年第几天?"); int dayInYear = Convert.ToInt32(Console.ReadLine()); //查询日期 int remainMonth; int remainDay = dayInYear; int copyDayInYear=dayInYear; for (remainMonth=1;remainMonth<=12;remainMonth++) { remainDay = dayInYear; dayInYear -= month[remainMonth]; if (dayInYear <= 0) break; } Console.WriteLine("该日日期为{0}月{1}日。", remainMonth, remainDay); //确认已知日期为该年第几天 Console.WriteLine("1)周一\n2)周二\n3)周三\n4)周四\n5)周五\n6)周六\n7)周日"); Console.WriteLine("请分三次输入已知的该年__月__日是星期__?"); int knownMonth=Convert.ToInt32(Console.ReadLine()); int knownDay = Convert.ToInt32(Console.ReadLine()); int knownWeekDate = Convert.ToInt32(Console.ReadLine()); int knownDayInYear=0; for (int i = 1; i < knownMonth; i++) knownDayInYear += month[i]; knownDayInYear += knownDay; Console.WriteLine("已知日期的天数:{0}",knownDayInYear); //查询礼拜 int weekDate=0; if (copyDayInYear > knownDayInYear) //已知日期晚于查询日期 { weekDate = (copyDayInYear - knownDayInYear + knownWeekDate) % 7; } else if ((copyDayInYear < knownDayInYear)&&(knownDayInYear-copyDayInYear>=7)) //已知日期早于查询日期 { weekDate = knownWeekDate+7-((knownDayInYear - copyDayInYear) % 7); } else if ((copyDayInYear < knownDayInYear) && (knownDayInYear - copyDayInYear <7)) { weekDate = 7 - (knownDayInYear - copyDayInYear - knownWeekDate+7) % 7; //考虑到括号内小于零的情形 } else Console.WriteLine("Are you kidding me?"); Console.WriteLine("查询日期的礼拜:{0}", (Week)weekDate); Console.ReadKey(); } } }

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧