C# 错误CS1022:需要类型或命名空间定义,或文件结尾
我正在为andriod/ios创建一个消息传递应用程序,但我对c#和网络完全陌生,我已经按照简单套接字教程的第一步开始了网络()的学习,但我发现了一个错误: 错误“CS1022:类型或命名空间定义,或应为文件结尾” 我假设它与名称空间有关,因为我是c#新手,实际上不了解名称空间的作用,但我的编译器说没有错误(如果这有区别的话,我使用visual studio代码),但可能是其他原因C# 错误CS1022:需要类型或命名空间定义,或文件结尾,c#,sockets,compiler-errors,namespaces,tcpserver,C#,Sockets,Compiler Errors,Namespaces,Tcpserver,我正在为andriod/ios创建一个消息传递应用程序,但我对c#和网络完全陌生,我已经按照简单套接字教程的第一步开始了网络()的学习,但我发现了一个错误: 错误“CS1022:类型或命名空间定义,或应为文件结尾” 我假设它与名称空间有关,因为我是c#新手,实际上不了解名称空间的作用,但我的编译器说没有错误(如果这有区别的话,我使用visual studio代码),但可能是其他原因 using System; using System.Collections.Generic; using Sys
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
namespace server_test
{
class program
{
static void main(string[] args)
{
IPAdress ip = Dns.GetHostEntry("localhost").AdressList[0];
TcpListener server = new TcpListener(ip, 8080);
TcpClient client = default(TcpClient);
try
{
server.Start();
Console.WriteLine("server started...");
Console.ReadLine();
}catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
}
}
}
它应该说服务器启动了……”或抛出一个例外,但这是我每次得到的:
[正在运行]mono“C:\Users\Aidan\AppData\Roaming\Code\User\cs script.User\cscs.exe”“d:!计算机科学!!NEA\测试内容\networking\server\u test\program.cs“
错误:无法编译指定的文件
csscript.CompilerException:d:!computer science!!NEA!\test stuff\networking\server\u test\program.cs(7127):应为错误CS1513:}
d:!computer science!!NEA!\test stuff\networking\server\u test\program.cs(37,1):错误CS1022:类型或命名空间定义,或预期文件结尾
在csscript.CSExecutor.ProcessCompilenResult(System.CodeDom.Compiler.CompilerResults结果,System.CodeDom.Compiler.CompilerParameters编译器参数,CSScriptLibrary.ScriptParser解析器,System.String脚本文件名,System.String汇编文件名,System.String[]附加依赖项)[0x00102]in:0
在:0中的csscript.CSExecutor.Compile(System.String scriptFileName)[0x0080d]处
位于:0中的csscript.CSExecutor.ExecuteImpl()[0x005a1]
[完成]在1.795秒内退出,代码=1
您缺少命名空间导入 加
并将键入的
地址列表
修复为地址列表
您缺少名称空间导入
加
并将键入的
地址列表
修改为地址列表
错误显示文件无法编译。因此,很可能是编译器错误。我猜如果不是键入,ipaddress的拼写将缺少一个d,因此地址列表也将丢失
IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0];
该错误显示文件无法编译。因此,很可能是编译器错误。我猜如果不是打字错误,下面是ipaddress的拼写缺少d,因此是AddressList
IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0];
两个答案都是正确的 无法使用System.Net。 地址列表中有一个输入错误 还有一个问题是——主功能应该用大写字母M拼写为“main” 完整程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
namespace server_test
{
class program
{
static void Main(string[] args)
{
IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0];
TcpListener server = new TcpListener(ip, 8080);
TcpClient client = default(TcpClient);
try
{
server.Start();
Console.WriteLine("server started...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
}
}
}
两个答案都是正确的 无法使用System.Net。 地址列表中有一个输入错误 还有一个问题是——主功能应该用大写字母M拼写为“main” 完整程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
namespace server_test
{
class program
{
static void Main(string[] args)
{
IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0];
TcpListener server = new TcpListener(ip, 8080);
TcpClient client = default(TcpClient);
try
{
server.Start();
Console.WriteLine("server started...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
}
}
}
IMO,在进入高级主题(即网络)之前,你真的应该先学习基础知识(即
名称空间
是什么)。IMO,在进入高级主题(即网络)之前,你真的应该先学习基础知识(即名称空间
是什么)。谢谢,我不敢相信我错过了这一点,把“主要为美沙克解决了这个问题,真不敢相信我错过了,资本化的“主要”为我解决了这个问题