如何在.NET中组织类似于#region/#endregion的代码?

发布于 2024-08-06 17:20:09 字数 136 浏览 5 评论 0原文

随着代码变得越来越大,保持一切井井有条变得越来越困难。当我在 .NET 中开发时,我非常喜欢的一件事是#region/#endregion,它能够以逻辑组的形式组织代码,并使进一步的组织变得更加容易。

有谁知道Java中是否有类似的代码组织?

While the code is growing big it is getting harder and harder to keep everything well organized. One thing I liked very much the time I developed in .NET was #region/#endregion which enabled to organize the code in logical groups and made further organization much easier.

Does anyone know whether there is any similar code organization possible in Java?

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

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

发布评论

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

评论(6

老街孤人 2024-08-13 17:20:10

这是 Visual Studio 的功能,而不是 .NET。您必须查看您选择的 Java IDE,看看它们有哪些选项。

That is a feature of Visual Studio, not .NET. You would have to look into your Java IDE of choice and see what options they have.

一萌ing 2024-08-13 17:20:10

区域的问题在于,它们可以使充满数千行意大利面条式代码的文件乍一看看起来紧凑、干净且组织良好,但事实并非如此。

如果单个文件变得难以管理,请考虑一下您如何构建您的类,以及是否有一些东西可以重构到它们自己的类或方法中?

当我开始 .net 时,我对这个地区感到非常高兴,但现在我想我已经好几年没有写过一个了。当我第一次打开一个包含 5 个区域的文件时,它们在我眼中失去了所有价值,我想,“嗯……足够简单”,只是为了扩展一个区域并获得几千行毫无意义的代码。

The problem with regions is they can make files filled with thousands of lines of spaghetti code look like they are compact, clean and well organized at first glance, which they are not.

If a single file is getting unmanageable, think about how you've structured your classes and is there things you can refactor out into their own classes or methods?

I got very region happy when I started .net and now I don't think I've written one in years. They lost all value in my eyes the first time I opened a file with 5 regions, thought, "Hmm...simple enough" only to expand one and get a few thousand lines of code that made no sense whatsoever.

情话已封尘 2024-08-13 17:20:10

不,Java 没有这样的东西。如果有的话,您应该获得一个更好的文本编辑器,它允许任意代码折叠或基于注释的代码折叠。

No, Java doesn't have anything like that. If anything you should get a better text editor that allows for arbitrary code folding or code folding based on comments.

子栖 2024-08-13 17:20:10

在 Java 中,您使用和项目来组织代码。

In Java, you use packages and projects to organize your code.

浅浅 2024-08-13 17:20:09

这在 netbeans 中有效:

// <editor-fold defaultstate="collapsed" desc=" Region Name ">

... Enter Code Block here ...

// </editor-fold>

This works in netbeans:

// <editor-fold defaultstate="collapsed" desc=" Region Name ">

... Enter Code Block here ...

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