You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决CS0105警告:System的using指令在命名空间中重复出现

修复CS0105警告的方法

这个警告的核心原因是同一个命名空间范围内重复引入了System命名空间。针对你的代码,有两种简单的修复方式:

方式一:移除重复的using System;声明

如果你的项目已经通过全局配置(比如.NET 6+的隐式全局引入)自动包含了System,或者你在代码其他位置(同一文件其他部分、项目内其他文件)已经声明过using System;,直接删除当前文件顶部的using System;即可:

namespace HelloWorld {
  class Program {
    static void Main(string[] args) {
      Console.WriteLine("Hello World!");    
    }
  }
}

方式二:将using语句移到命名空间内部(如需手动控制引入范围)

如果需要明确控制命名空间的引入范围,可以把using System;放到namespace HelloWorld内部,确保只在该命名空间内引入一次:

namespace HelloWorld {
  using System;

  class Program {
    static void Main(string[] args) {
      Console.WriteLine("Hello World!");    
    }
  }
}

额外提示:你的代码末尾多了一个多余的分号;,虽然不影响运行,但不符合C#编码规范,建议一并删除。

内容的提问来源于stack exchange,提问作者Mahfuz Swaron

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 16:30:57