using System;
namespace Codes
{
class Program
{
static void Main(string[] args)
{
String name = RandomNames();
Console.Write(name);
Console.ReadKey();
}
public static string RandomNames()
{
Random numGen = new Random();
string vowel = "aeiou";
string conso = "bcdfghjklmnpqrstvwxyz";
int nameLen = numGen.Next(4,10);
string result = "";
for (int i = 0; i < nameLen; i++)
{
if (i % 2)
{
result += vowel[numGen.Next(0, 4)]; // 4 is final index of vowel.
}
else
{
result += conso[numGen.Next(0, 20)]; // 20 is final index of consonants.
}
}
return result;
}
}
它说 if 语句中的“i”不能隐式地将类型“int”转换为“bool”,我不知道有什么问题,因为它已经是一个 int for 循环
i % 2
是 int 类型,而不是 bool 类型,C# 无法自动进行转换,因此只需尝试:
i % 2 != 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句