MessageBox.Show()的问题

Tim*_*Tim 2 .net c# messagebox winforms

我是新手代码,大多数工作都有效,但我无法运行此代码.有人可以帮忙吗?

我试过,using System.Forms但它显示缺少命名空间.当我用using System.Windows.Forms这个消息消失了.它不允许我同时使用它们.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(@"file.csv");
            // for set encoding
            // StreamReader sr = new StreamReader(@"file.csv", Encoding.GetEncoding(1250));

            string strline = "";
            String[] _values = null;
            int x = 0;
            while(!sr.EndOfStream)
            {
                strline = sr.ReadLine();
                _values = strline.Split(',');
                if (_values.Length >= 6 && _values[0].Trim().Length > 0)
                {
                    MessageBox.show(_values[1]);
                }
            }
            sr.Close();

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Jam*_*iec 5

没有这样的命名空间System.Forms,您尝试使用的类(MessageBox)所在的类System.Windows.Forms.通过更正您的using陈述,错误消失了.

请记住,您必须System.Windows.Forms.dll在控制台应用程序中引用此类.


Dmi*_*hin 5

您需要System.Windows.Forms.dll在项目中引用。是详细的说明。