c# - 无法键入 System.IO.Ports 速记

标签 c# namespaces serial-port

我有以下代码,但仍然必须键入完整路径才能使用 System.IO.Ports 命名空间,即使我有 using 子句。我的引用文献列表中是否遗漏了什么?

= new SerialPort 返回错误 5 'SerialPort' 是一个 'namespace' 但被用作 'type'

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace SerialPort
{
    public partial class Form1 : Form
    {
        System.IO.Ports.SerialPort counter = new SerialPort("COM5");
        public Form1()
        {
            InitializeComponent();

        }

谢谢

最佳答案

您正在声明 SerialPort 的命名空间。不要那样做。这就是导致问题的原因。

您所要做的就是更改 namespace ,一切都会好起来的。您可以按照 Honza 的要求使用别名,但我认为如果您只是重命名 namespace ,代码对每个人来说都会更清晰。

关于c# - 无法键入 System.IO.Ports 速记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13443389/

相关文章:

networking - 串行通讯在 WinXP 中死机

c# - 为什么 Form_Load 事件已经捕获了所有异常?

c# - 如何从 WPF DataGrid 的单元格中读取值?

c# - Getter Setter 约定

python共享全局模块变量问题

c - 将串行输入读取到 C 变量

c# - 使用共享契约(Contract)将电子邮件地址添加到电子邮件应用程序的字段中?

PHP fatal error : Class 'Facebook\\Entities\\AccessToken

namespaces - 使用 : http://docs. oasis-open.org/ws-sx/ws-trust/200512 或 http ://schemas. xmlsoap.org/ws/2005/02/trust 中的哪一个?

matlab - 使用 'fscanf' 从 MATLAB 中的串行线读取数据时解释零