在您的代码中输入名称冲突 [英] type name collisions in your code
本文介绍了在您的代码中输入名称冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何确保代码中没有任何类型名称冲突?
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:
- 使用描述性名称:这样很难使两个不同的事物具有完全相同的名称.
- 使用命名空间将事物基于其主题进行分组.例如,考虑
System.Timers.Timer
和System.Threading.Timer
类:这两个类具有相同的名称,但是在两个不同的名称空间中定义,因为它们在相似的环境中却做同样的事情.
- Use descriptive names: this way it''s difficult that two different things has exactly the same name.
- Use namespaces to group things basing on their subject. As an example think about the
System.Timers.Timer
andSystem.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屋!
查看全文