How do I collapse selected chunks of code in Visual Studio 2008?

前端 未结 3 1619
故里飘歌
故里飘歌 2020-12-30 22:59

In Visual Studio 2008: Is there a way for me to customly collapse bits of code similar to like how I can automatically collapse chunks of comments?

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 23:27

    TheSam is right, you can create collapsible chunks with the #pragma region and #pragma endregion statements.

    Here is a sample:

    int main(array args)
    {
    
    
        Console::WriteLine(L"This");
        Console::WriteLine(L"is");
        Console::WriteLine(L"a");
        #pragma region
        Console::WriteLine(L"pragma");
        Console::WriteLine(L"region");
        #pragma endregion
    
        Console::WriteLine(L"test.");
        return 0;
    }
    

    In the above sample, everything between the samples can be collapsed.

    You can also specify what text is displayed when it is collapsed. You can do that like this:

    #pragma region The displayed text
    

    That would obviously display "The displayed text" when the region was collapsed.

提交回复
热议问题