C#如何在一个消息(控制台应用程序),显示该阵列 [英] c# How do i display this array in a messagebox (console application)

查看:249
本文介绍了C#如何在一个消息(控制台应用程序),显示该阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮我用一个消息框,为每个标签显示两列随机数和平方?

  const int的NUM_ROWS = 10;
    const int的NUM_COLS = 2;        INT [,] randint =新INT [NUM_ROWS,NUM_COLS]
        随机randNum =新的随机();        对于(INT行= 0;&行LT; randint.GetLength(0);排++)
        {
            randint [排,0] = randNum.Next(1,100);
            randint [行1] = randint [行,0] * randint [行,0];        Console.Write(的String.Format({0,5:D} {1,5:D} \\ n,randint [排,0],randint [行1]));


解决方案

我通过添加System.Windows.Forms的引用到我的控制台应用程序实现的,并得到你想要的结果。这里是我的code:

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;
使用System.Windows.Forms的;
命名空间ConsoleApplication6
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            const int的NUM_ROWS = 10;
            const int的NUM_COLS = 2;            INT [,] randint =新INT [NUM_ROWS,NUM_COLS]
            随机randNum =新的随机();            对于(INT行= 0;&行LT; randint.GetLength(0);排++)
            {
                randint [行,0] = randNum.Next(1,100);
                randint [行1] = randint [行,0] * randint [行,0];                Console.Write(的String.Format({0,5:D} {1,5:D} \\ n,randint [排,0],randint [行1]));                MessageBox.Show(的String.Format({0,5:D} {1,5:D} \\ n,randint [排,0],randint [行1]));
                Console.ReadKey();
            }
        }
    }
}

我的输出:结果

此外,虽然这不是要求,但为了以防万一补充参考System.Windows.Form看就引用右键单击在解决方案资源管理器中,选择.NET选项卡,然后preSS选择所需的dll后确定。干杯!


Can anyone help me use a message box to display the random number and the square in two columns with a label for each?

    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]));

解决方案

I have achieved it by adding reference of System.Windows.Forms to my console application and got the result you desired. Here is my code:

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();
            }
        }
    }
}  

My output:
Also though this is not asked but just in case to add reference to System.Windows.Form look right click on the references in your solution explorer and select .Net tab and then press ok after selecting the desired dll. Cheers!

这篇关于C#如何在一个消息(控制台应用程序),显示该阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆