Книга: C# 2008 Programmer
#region and #endregion
#region and #endregion
The #region
and #region
preprocessor directives are used in conjunction with Visual Studio's Code Editor. Let's work with the following example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestDefine {
class Program {
static void Main(string[] args) {
//---implement ions here---
}
private void Method1() {
//---implementations here---
}
private void Method2() {
//---implementations here---
}
private void Method3() {
//---implementations here---
}
}
}
Often, you have many functions that perform specific tasks. In such cases, it is often good to organize them into regions so that they can be collapsed and expanded as and when needed. Using this example, you can group all the methods — Method1()
, Method2()
, and Method3()
— into a region using the #region and #region preprocessor directives:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestDefine {
class Program {
static void Main(string[] args) {}
#region "Helper functions"
private void Method1() {
//---implementations here---
}
private void Method2() {
//---implementations here---
}
private void Method3() {
//---implementations here---
}
#endregion
}
}
In Visual Studio 2008, you can now collapse all the methods into a group called "Helper functions"
. Figure 3-19 shows the Code Editor before and after the region is collapsed.
Figure 3-19
The #region
and #region
preprocessor directives do not affect the logic of your code. They are used purely in Visual Studio 2008 to better organize your code.
- Разработка приложений баз данных InterBase на Borland Delphi
- Open Source Insight and Discussion
- Introduction to Microprocessors and Microcontrollers
- Chapter 6. Traversing of tables and chains
- Chapter 8. Saving and restoring large rule-sets
- Chapter 11. Iptables targets and jumps
- Chapter 5 Installing and Configuring VirtualCenter 2.0
- Chapter 16. Commercial products based on Linux, iptables and netfilter
- Appendix A. Detailed explanations of special commands
- Appendix B. Common problems and questions
- Appendix E. Other resources and links
- IP filtering terms and expressions