namespace Practice69
{
class Program
{
static void Main(string[] args)
{
string[] alphabet;
alphabet = new string[] { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m" };
// making the keyboard layout alphabetical and print horizontally
Array.Sort(alphabet);
for (int i = 0; i < 1; i++)
{
Console.WriteLine(String.Join(" ", alphabet), alphabet[i]);
}
// making the alphabet print out reverse alphabetical and horizontally
Array.Reverse(alphabet);
for (int i = 0; i < 1; i++)
{
Console.WriteLine(String.Join(" ", alphabet), alphabet[i]);
}
// making the whole alphabet print out radomly
Random randAlphabet = new Random();
for (int i = 0; i < 1; i++)
{
Console.WriteLine(String.Join(" ", alphabet), alphabet[i]);
foreach (string value in alphabet)
{
randAlphabet.Next();
}
我希望它能打印出一个b/c,然后输出一个b/c,然后输出一个b/c同样的东西,但顺序相反,而且是随机的。
-
你不需要任何循环
-
你已经有排序和反向排序钉,只是摆脱循环!
-
随机位可以写成LINQ查询(一个秘密循环!)
这个怎么样?
class Program
{
static void Main(string[] args)
{
char[] alphabet;
alphabet = new char[] { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm' };
// making the keyboard layout alphabetical and print horizontally
Array.Sort(alphabet);
Console.WriteLine(string.Join(' ', alphabet));
// making the alphabet print out reverse alphabetical and horizontally
Array.Reverse(alphabet);
Console.WriteLine(string.Join(' ', alphabet));
// making the whole alphabet print out randomly
Random randAlphabet = new Random();
alphabet = alphabet.OrderBy(x => randAlphabet.Next()).ToArray();
Console.WriteLine(string.Join(' ', alphabet));
}
}