gpt4 book ai didi

c# 我如何在消息框(控制台应用程序)中显示此数组

转载 作者:太空宇宙 更新时间:2023-11-03 20:00:15 25 4
gpt4 key购买 nike

谁能帮我用一个消息框在两列中显示随机数和正方形,每列都有一个标签?

    const int NUM_ROWS = 10;
const int NUM_COLS = 2;

int[,] randint = new int [NUM_ROWS,NUM_COLS];
Random randNum = new Random();

for (int row = 0; row < randint.GetLength(0); row++)
{
randint[row,0] = randNum.Next(1,100);
randint[row,1] = randint[row,0]*randint[row,0];

Console.Write(string.Format("{0,5:d} {1,5:d}\n", randint[row,0], randint[row,1]));

最佳答案

我通过将 System.Windows.Forms 的引用添加到我的控制台应用程序来实现它,并获得了您想要的结果。这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
const int NUM_ROWS = 10;
const int NUM_COLS = 2;

int[,] randint = new int[NUM_ROWS, NUM_COLS];
Random randNum = new Random();

for (int row = 0; row < randint.GetLength(0); row++)
{
randint[row, 0] = randNum.Next(1, 100);
randint[row, 1] = randint[row, 0] * randint[row, 0];

Console.Write(string.Format("{0,5:d} {1,5:d}\n", randint[row, 0], randint[row, 1]));

MessageBox.Show(string.Format("{0,5:d} {1,5:d}\n", randint[row, 0], randint[row, 1]));
Console.ReadKey();
}
}
}
}

我的输出:
Output此外,虽然这不是要求,但以防万一添加对 System.Windows.Form 的引用,请右键单击解决方案资源管理器中的引用并选择 .Net 选项卡,然后在选择所需的 dll 后按确定。干杯!

Adding ref Selecting desired reference

关于c# 我如何在消息框(控制台应用程序)中显示此数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29313546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com