因此,我正在用C#编写一个Windows控制台应用程序,用于短波HAM Radio DX爱好者在他们的桌面上查看数字电台和奇怪的广播时间。我使用Visual Studio社区版作为我的编译器。
发生的情况是编译器返回以下错误:
这个应用程序的工作原理是通过连接到priyom.orgs IRC频道,然后用户可以使用!n命令来查找下一个广播电台。但是我找不到没有返回的值:enter image description here
[1]: https://i.stack.imgur.com/gguPR.png
Here is the code:
using System;
using System.IO;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace irc_bot
{
class Program
{
private const string server = "chat.freenode.net";
private const string gecos = "Cerk";
private const string nick = "Priyomwindowsapp";
private const string ident = "Priyomwindowsapp";
private const string channel = "#priyom";
static string Main(string[] args)
{
using (var client = new TcpClient())
{
Console.WriteLine("Welcome to Numbers Station Finder. From here you can search for Number Station broadcast times and other shortwave / HAM radio oddities right from your Windows desktop. I will also present a link to navigate to in your web browser to listen in real time. For note, I use priyom.orgs IRC server. While on the IRC server you will have the nickname Priyomwindowsapp. To display the next signal to broadcast type !n. To search for a signal type !n space enigma ID (!n HM01 for example). Program C 2020 keifmeister.");
Console.WriteLine($"Connecting to {server}");
client.Connect(server, 6667);
Console.WriteLine($"Connected: {client.Connected}");
using (var stream = client.GetStream())
using (var writer = new StreamWriter(stream))
using (var reader = new StreamReader(stream))
{
writer.WriteLine($"USER {ident} * 8 {gecos}");
writer.WriteLine($"NICK {nick}");
// identify with the server so your bot can be an op on the channel
writer.WriteLine($"PRIVMSG NickServ :IDENTIFY {nick}");
writer.Flush();
while (client.Connected)
{
var data = reader.ReadLine();
if (data != null)
{
var d = data.Split(' ');
Console.WriteLine($"Data: {data}");
if (d[0] == "PING")
{
writer.WriteLine("PONG");
writer.Flush();
}
if (d.Length > 1)
{
switch (d[1])
{
case "376":
case "422":
{
writer.WriteLine($"JOIN {channel}");
// communicate with everyone on the channel as soon as the bot logs in
Console.WriteLine("Enter username to be logged into:");
string message = Convert.ToString(Console.ReadLine());
writer.WriteLine(message);
writer.Flush();
break;
}
case "PRIVMSG":
{
if (d.Length > 2)
{
if (d[2] == nick)
{
// someone sent a private message to the bot
var sender = data.Split('!')[0].Substring(1);
var message = data.Split(':')[2];
Console.WriteLine($"Message: {message}");
// handle all your bot logic here
writer.WriteLine($@"PRIVMSG {sender} : {message}");
writer.Flush();
}
}
break;
}
}
}
}
}
}
}
}
}
}任何帮助都是非常感谢的。
发布于 2020-07-31 10:41:42
您将从Main返回一个string,因此静态分析认为您希望返回一个结果。很可能你实际上想要:
static void Main(string[] args)其他资源
Main() and command-line arguments (C# Programming Guide)
任务Main可以具有void、int或从C# 7.1开始的
、Task或Task返回类型。
来自Hayden的有价值的评论
还确保您的项目输出类型是控制台应用程序(在Visual Studio中右键单击您的项目>属性>应用程序标签)。
https://stackoverflow.com/questions/63184974
复制相似问题