using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{ string[] aa = new string[] { "aa", "bb", "cc" }; int i=aa.Length;
while (i < 3)
{
string ii = aa[i];
Console.Write(ii); i--;
}
}
}
}为何我这个数组不输出
如何让这个数组依次输出
把代码贴出来
谢谢
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{ string[] aa = new string[] { "aa", "bb", "cc" }; int i=aa.Length;
while (i < 3)
{
string ii = aa[i];
Console.Write(ii); i--;
}
}
}
}为何我这个数组不输出
如何让这个数组依次输出
把代码贴出来
谢谢
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] aa = new string[] { "aa", "bb", "cc" }; foreach (string a in aa)
{
Console.Write(a);
} Console.ReadLine();
}
}
}
while (i < 3)
{
string ii = aa[i];
Console.Write(ii); i--;
}
改为:
foreach(string s in aa)
{
Console.Write(s);
}
Console.ReadLine();
int i=aa.Length;//这里的i肯定是3啊
while (i < 3) //3在这里不满足条件,当然不执行循环改成这样就可以了
while (i > -1)
{
string ii = aa[i];
Console.Write(ii);
i--;
}
while (i < 3) //因为i=3,因此没有进入While循环
也可以这样改:
int i=aa.Length-1;
while (i >=0)
{
string ii = aa[i];
Console.Write(ii);
i--;
}
Console.ReadLine();
using System.Collections.Generic;
using System.Text;
using System.Collections; namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string[] aa = new string[] { "aa", "bb", "cc" }; int i=aa.Length - 1; while (i < 3 && i >= 0)
{
string ii = aa[i];
Console.Write(ii);
i--;
}
}
}
}
string[] aa = new string[] { "aa", "bb", "cc" };
int i=aa.Length - 1;
while (i < 3)
{
string ii = aa[i];
Console.Write(ii); i--;
}
你的int i=aa.Length;
此时I=3 然后你再while (i < 3)
此时永远不会进入循环,自然不会输出.可以把while (i < 3)
改成while (i < 2 && i>-1)
3楼错在i的初始值上,应该是int i=aa.Length-1;
7楼,i>-1
8楼,死循环了
9楼,i<3而不是i<2
其他就不说了。。按顺序输出的话是这样的:using System;
using System.Collections.Generic;
using System.Text;
using System.Collections; namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string[] aa = new string[] { "aa", "bb", "cc" }; int i=0; while (i < 3)
{
string ii = aa[i];
Console.Write(ii);
i++;
}
}
}
}
改成这样可以显示的
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{ string[] aa = new string[] { "aa", "bb", "cc" }; int i = aa.Length; while (i > 0)
{
string ii = aa[i-1];
Console.Write(ii);
i--;
}
}
}
}