我开始学习c#并完成这项任务.我已经这样做了这是代码:
string y = "";
int count = 0;
string x = "";
string[] arr = new string[100000000];
for (int i = 0; i < 100000000; i++)
{
x = i.ToString() + x;
}
Console.WriteLine(x);
for (int j = 0; j < x.Length; j++)
{
y = x.Substring(j, 1);
switch (y)
{
case "1":
count ++;
break;
default:
break;
}
}
Console.WriteLine(count);
Run Code Online (Sandbox Code Playgroud)
代码在小范围(0到1000)的情况下正常工作但在运行它的范围为1亿时它不会产生任何结果(我等待但没有输出)加上看起来我的代码不是有效的方式.我现在的问题是这个代码中的问题是什么,以及是否有更好的解决方案来完成这项任务.
c# ×1