我需要创建一个用随机数填充数组的应用程序。我编写了整个代码并且它可以工作,但数字没有显示在控制台窗口中。代码有什么问题?谢谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Arrays
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[10];
Random randomNumbers = new Random();
for (int i = 0; i < array.Length; i++)
{
int randomValue = randomNumbers.Next(0,500);
array[i] = randomValue;
}
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine("The array value is: ", array[i]);
}
}
}
}
答案 0 :(得分:6)
您可以使用
Console.WriteLine("The array value is: {0}", array[i]);
或
Console.WriteLine("The array value is: " + array[i]);
但你写的是什么,
Console.WriteLine("The array value is: ", array[i]);
完全没有告诉控制台你在哪里以及如何使用array [i]变量。
答案 1 :(得分:2)
Console.WriteLine("The array value is: {0}", array[i]);
您必须在格式字符串中指明要打印某些值。
答案 2 :(得分:1)
//Console.WriteLine("The array value is: ", array[i]);
Console.WriteLine("The array value is: {0}", array[i]);
答案 3 :(得分:1)
Console.WriteLine(“数组值为:{0}”,array [i]);
答案 4 :(得分:0)
你错过了
Console.ReadLine();
Console.WriteLine();
之后
正如其他人所提到的,为了让这一行与{0}
一起使用,您需要将其格式化为字符串,
Console.WriteLine(string.Format("The array value is: {0}", array[i]));
答案 5 :(得分:0)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Coefficient Of x (Positive): ");
int coef = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Value Of c: ");
int c = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("From? (Positive)");
int from = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("To? (Positive)");
int to = Convert.ToInt32(Console.ReadLine());
Console.Clear();
int[] y_val = new int[(to - from) + 1];
int counter = 0;
for (int i = to; i >= from; i--)
{
y_val[counter] = ((coef * i) + c);
counter++;
}
int x = 0;
for (int i = to; i >= from; i--)
{
if (y_val[x] == ((coef * i) + c))
{
if (y_val[x] >= 10)
{
Console.WriteLine("{0}|", y_val[x]);
}
else
{
Console.WriteLine("0{0}|", y_val[x]);
}
for (int j = 0; j < i; j++)
{
Console.Write(" ");
}
Console.Write("*");
Console.WriteLine();
}
x++;
}
Console.WriteLine("______________________________________________________________");
Console.WriteLine("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23");
Console.ReadKey();
}
}
}
答案 6 :(得分:0)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("asd");
}
}
}