当前位置:  开发笔记 > 编程语言 > 正文

在visual studio中创建一个C#dll

如何解决《在visualstudio中创建一个C#dll》经验,为你挑选了1个好方法。

我正在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#的新手.为什么会出错?



1> 小智..:

你不能只把代码放在你的类中.您需要使用代码定义af方法.喜欢

public void MyMethod()
{
    //you code here
}

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有