最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net中C#的global关键字用法
时间:2022-06-25 08:21:22 编辑:袖梨 来源:一聚教程网
如下代码:
代码如下 | 复制代码 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace globalFunc { class Program { static void Main(string[] args) { System sys = new System(); global::System.Console.WriteLine("global."); global::System.Console.ReadKey(); } } public class System { } } |
虽然using了一个System命名空间,但是下面还有一个public class System{ ... }类,这样的话,如果直接使用System.Console.WriteLine是会报错的,因为会找到就近的System类,那么这个System类里面没有Console。所以如果需要使用的话,就需要像上面一样,使用global::System.Console.WriteLine,因为使用global标记的类会从全局开始寻找,我的理解就是会从最外面逐渐向内部寻找System类。
相关文章
- 碧蓝航线的里雅斯特期待的便当时间皮肤有什么 04-30
- 明日之后踏浪逐星服装展示攻略 04-30
- 深空之眼幽月塞勒涅刻印搭配核心思路 04-30
- 明日之后红杉茶会护卫队首领BOSS有哪些 04-30
- CF手游段位奖励汇总攻略 04-30
- 无期迷途5-13怎么走攻略 04-30