一个简单的C#程序

来源:百度知道 编辑:UC知道 时间:2024/06/02 05:42:58
输入一个字符串,用foreach语句计算输入的字符串长度,并显示长度.

谢谢
为什么我不能运行? 说什么"System.Console"并不包含"WriteLine"的定义

string str="";
str=Console.ReadLine();
Console.Writeline(str.Length.ToString());//str.Length就是获取字符串长度
int l=0;
foreach(char x in str) //foreach是遍历的意思
{
l++;
}
Console.WriteLine(l.ToString());

string str="";
str=Console.ReadLine();
Console.Writeline(str.Length.ToString());//str.Length就是获取字符串长度
int l=0;
foreach(char x in str)
l++;
Console.WriteLine(l.ToString());