VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • vb.net 程序暂停指令_VB.NET中的区域指令

vb.net 程序暂停指令

When VB.NET 1.0 was introduced, one of the biggest changes was that all of Microsoft's generated source code was included and available to you as a programmer in your project. The older Visual Basic versions created indecipherable p-code that you couldn't see and couldn't change. Even though the generated code was in your program, it was a bad idea to change any of it. If you didn't know what you were doing, chances were high you'd break your project by changing Microsoft's generated code.

引入VB.NET 1.0时,最大的变化之一就是包含了Microsoft生成的所有源代码 ,并且可以作为项目中的程序员使用。 较早的Visual Basic版本创建了您无法看到且无法更改的难以理解的p代码。 即使生成的代码在您的程序中,更改它中的任何一个也是一个坏主意。 如果您不知道自己在做什么,那么很有可能通过更改Microsoft生成的代码来破坏项目。

In VB.NET 1.0, all this generated code was only protected by being enclosed in a Region section of the program, where it was one click away from being viewable and changeable as part of your source code. Beginning with VB.NET 2005 (Framework 2.0), Microsoft put it in an entirely different file using partial classes, but the Region directive is still available, and you can use it to organize your own code.

在VB.NET 1.0中,所有这些生成的代码仅通过被封装在程序的“区域”部分中而受到保护,在该区域中,一键单击即可将其作为源代码的一部分进行查看和更改。 从VB.NET 2005(Framework 2.0)开始,Microsoft使用局部类将它放在一个完全不同的文件中,但是Region指令仍然可用,您可以使用它来组织自己的代码。

This simple program shows how Region works:

这个简单的程序显示了Region的工作方式:

You could compile this into a DLL to protect it or use the partial class idea that Visual Studio uses or just make a separate class file, but the easiest way to keep it out of the way and still make it part of the same file is to use the Region directive. That makes the code look like this:

您可以将其编译为DLL以保护它,也可以使用Visual Studio使用的部分类思想,也可以只是制作一个单独的类文件,但最简单的方法是将其保留在同一个文件中,并使其成为同一文件的一部分。使用Region指令。 这使得代码看起来像这样:

Just surround the code you want to disappear with:

只需将您想消失的代码括起来:

For debugging purposes, you can use this as a way to bring parts of your code closer together so you can see them on the same screen:

出于调试目的,您可以使用此方法将代码的各个部分紧密结合在一起,以便可以在同一屏幕上看到它们:

You can't use a Region or an End Region inside a function or subroutine. In other words, this example below doesn't work:

您不能在函数或子例程内使用Region或End Region。 换句话说,下面这个例子 工作 :

That's OK. Visual Studio collapses subroutines without a Region directive. You can nest Regions. In other words, this does work:

没关系。 Visual Studio折叠没有Region指令的子例程。 您可以嵌套区域。 换句话说,这确实可行 :

If you borrow code from the internet, look for Regions in it before you add it to your code. Hackers have been known to embed bad stuff inside a Region to keep it from being noticed.

如果您从互联网借用代码,请先在其中查找区域,然后再将其添加到代码中。 众所周知,黑客会在区域内嵌入不良内容,以免被发现。

翻译自: https://www.thoughtco.com/the-region-directive-in-vbnet-3424253


相关教程