在您的代码中输入名称冲突 [英] type name collisions in your code

查看:78
本文介绍了在您的代码中输入名称冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确保代码中没有任何类型名称冲突?

What can you do to make sure you don’t have any type name collisions in your code?

推荐答案

不要将所有名称都命名为相同名称.
Don''t call everything the same name.


我认为,我们拥有名称空间的主要原因之一就是这个!

此外,更多的是遵循的编码标准和实践.
I think, one of the main reason why we have namespaces is this only!

Further, it''s more of coding standards and practices that one follow.


只有两件事:

Just two things:


  1. 使用描述性名称:这样很难使两个不同的事物具有完全相同的名称.
  2. 使用命名空间将事物基于其主题进行分组.例如,考虑System.Timers.TimerSystem.Threading.Timer类:这两个类具有相同的名称,但是在两个不同的名称空间中定义,因为它们在相似的环境中却做同样的事情.

  1. Use descriptive names: this way it''s difficult that two different things has exactly the same name.
  2. Use namespaces to group things basing on their subject. As an example think about the System.Timers.Timer and System.Threading.Timer classes: the two classes has the same name, but are defined on two different namespaces, as they do similar things but in different contexts.


这篇关于在您的代码中输入名称冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆