我正在visual studio express 2013中创建一个C#dll.我正在为我的程序的一部分创建一个dll,以便可以在需要时调用它.我的代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.Net.Sockets; namespace ClassLibrary2 { public class take_off { UdpClient udpClient = new UdpClient(5556); IPAddress send_to =IPAddress.Parse("192.168.1.1"); IPEndPoint sending_end_point =new IPEndPoint(send_to,5556); int seq; for(int i=0;i<30;i++) { System.Console.WriteLine("send landing command"); string buff1= String.Format("AT*REF={0},290717696\r",seq); seq=seq+1; UdpClient.Send(buff1, sending_end_point); } } }
我收到的错误很少:
Error 1 Identifier expected Error 9 Invalid token '(' in class, struct, or interface member declaration Error 11 Invalid token ')' in class, struct, or interface member declaration Error 10 Invalid token ',' in class, struct, or interface member declaration Error 8 Invalid token '+' in class, struct, or interface member declaration Error 6 Invalid token '++' in class, struct, or interface member declaration Error 7 Invalid token '=' in class, struct, or interface member declaration Error 4 Invalid token '30' in class, struct, or interface member declaration Error 3 Invalid token 'for' in class, struct, or interface member declaration Error 5 Type expected Error 2 Type or namespace definition, or end-of-file expected Error 12 Type or namespace definition, or end-of-file expected
我写的语法有错误吗?我是C#的新手.为什么会出错?
你不能只把代码放在你的类中.您需要使用代码定义af方法.喜欢
public void MyMethod() { //you code here }