使用“区域”有一些明显的缺点吗?

发布于 2024-10-20 22:46:45 字数 275 浏览 1 评论 0原文

可能的重复:
您对 C# 区域说“不”吗?

从编码的角度来看使用“区域”预处理器指令?

 #region name
     // some code block
 #end region

Possible Duplicate:
Do you say No to C# Regions?

Is there any obvious disadvantageous of using 'region' pre-processor directives from the coding point of view?

 #region name
     // some code block
 #end region

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

信仰 2024-10-27 22:46:45

我发现区域有助于将代码组织成逻辑部分。我见过很多来自受人尊敬的经常使用区域的程序员的例子。据我所知,这纯粹是装饰性的,不会产生任何影响。

I find that regions help organize code into logical sections. I've seen many examples from respected coders that regularly use regions. As far as I'm aware, it's purely cosmetic, and doesn't impact anything.

南街九尾狐 2024-10-27 22:46:45

如果按照预期使用它们,我不会说有任何缺点。它们的想法是在逻辑上分隔代码部分(区域)。

然而,如果它们嵌套得很深或者方法被放置在它们有意义的区域之外,事情可能会变得混乱。

I wouldn't say say there are any disadvantages at all, if they are used as they are intended. The idea of them is to logically separate sections (regions) of code.

However, if they are deeply nested or methods are put outside of a region in which they would make sense, things could get confusing.

同展鸳鸯锦 2024-10-27 22:46:45

需要注意的一个问题是,如果该区域关闭,Visual Studio“在当前文档中查找”将不会搜索该区域。

但是,在解决方案中查找或在项目中查找会找到它。

One gotcha to be aware of is that if the region is closed, Visual Studio "Find in current document" will not search through this region.

Find in Solution, or Find in Project will find it however.

女皇必胜 2024-10-27 22:46:45

我什么也看不见。不过,有几件事需要记住:页面上的行数过多并不是借口(例如具有 2000 行的表单。即使对于区域,这也很糟糕,因为这意味着您正在混合逻辑层)。

我个人喜欢使用区域,但有些人更喜欢看到他们的整个代码。这仅与偏好有关。

I can't see any. There are few things to keep in mind though: It is not an excuse to have too many lines on your page (like a form with 2000 lines. That's plain bad, even with regions, because it means you are mixing the logic layers).

I personnaly like to use regions, but some people prefer to see their whole code. It's only about preference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文