gpt4 book ai didi

c# - MessageBox.Show() 的问题

转载 作者:行者123 更新时间:2023-11-30 18:55:07 70 4
gpt4 key购买 nike

我是代码新手,大多数东西都可以工作,但我无法运行这段代码。有人可以帮忙吗?

我尝试使用 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();

}
}
}

最佳答案

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

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

关于c# - MessageBox.Show() 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7977298/

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