c#中使用其他.cs文件内容

// 文件结构
demo
  |
  cs---
  |	  |
  |	  cs1.cs
  |   floder.cs
  Program.cs
  |
  P.cs
// P.cs
using System;
namespace  P
{
    public class Son
    {
        public static void fun(){
            Console.WriteLine("this\'s Son");
        }
        
        public void fun1(){
            Console.WriteLine("p is required");
        }
    }
}
// cs1.cs
using System;
namespace cs2
{
    public class cs1
    {
        public static void fun(){
            Console.WriteLine("cs2");
        }
    }
}
// floder.cs
using System;
namespace cs
{
    public class floder
    {
        public static void fun(){
            Console.WriteLine("this is floder\'s .cs");
        }
    }
}
// Program.cs
using System;
using P;
// 略
static void Main(string[] args) {
   P.Son.fun(); //this's Son
   cs.floder.fun(); //this is floder's .cs
   cs2.cs1.fun(); //cs2
   Son a = new Son();
   a.fun1(); //p is required
}

总结

可以通过using + namespace的值引用对应的文件
然后就可以使用了,
也可以直接通过namespace点式访问静态数据

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用PCANBasic.csC#建立CAN通信的基本步骤: 1. 引用PCANBasic.dll文件 在Visual Studio右键单击解决方案资源管理器的“引用”文件夹,选择“添加引用”,选择“浏览”,找到PCANBasic.dll文件并添加。 2. 定义变量 在代码定义以下变量: ```csharp private TPCANHandle m_PcanHandle; private TPCANMsg m_TpcanMsg; private TPCANStatus m_Status; ``` 3. 初始化PCAN通道 在需要使用PCAN通道的地方,使用以下代码初始化: ```csharp m_PcanHandle = PCANBasic.PCAN_USBBUS1; //设置通道 m_Status = PCANBasic.Initialize(m_PcanHandle, TPCANBaudrate.PCAN_BAUD_500K); //初始化通道 ``` 4. 发送CAN帧 使用以下代码发送一帧CAN消息: ```csharp m_TpcanMsg = new TPCANMsg { ID = 0x123, MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD, LEN = 8, DATA = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 } }; m_Status = PCANBasic.Write(m_PcanHandle, ref m_TpcanMsg); ``` 5. 接收CAN帧 使用以下代码接收CAN消息: ```csharp m_TpcanMsg = new TPCANMsg(); m_Status = PCANBasic.Read(m_PcanHandle, out m_TpcanMsg, null); if (m_Status == TPCANStatus.PCAN_ERROR_OK) { Console.WriteLine($"Received {m_TpcanMsg.LEN} bytes of data from ID {m_TpcanMsg.ID:X}."); } ``` 6. 关闭PCAN通道 使用以下代码关闭PCAN通道: ```csharp m_Status = PCANBasic.Uninitialize(m_PcanHandle); ``` 以上是使用PCANBasic.csC#建立CAN通信的基本步骤,可以根据需要进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值