关于C#中的for语句的一点问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 00:46:11
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s;
char[] a;
Console.WriteLine("Please input a string");
s = Console.ReadLine();
a = s.ToCharArray();
for (int x = a.Length; x < 0;x++ )
{
Console.WriteLine(a[x-1]);
}
}
}
}

我想让这个程序把输入的字符串反向输出,用while,foreach等都可能实现,不过用for就是做不出来,源程序在上面,达人看看有没有什么问题啊!
上面发的东西有点笔误,for的条件是x--,不过它没有东西输出

当然有问题,是死循环。
for (int x = a.Length; x < 0;x++ ) a.Length最小为0,不可能小于0,而且以后每次++,一直无限循环下去。
应该是for (int x = a.Length; x > 0;x-- )

for (int x = a.Length; x < 0;x++ ) // x--

for (int x = a.Length; x > 0;x-- )