c#中的#pragma region

时间:2013-06-14 07:18:40

标签: c# visual-studio-2012 pragma

在我用C#编写的以下程序中:

static void Main(string[] args)
        {
            paramsAndOptionalTest(1,2);

#pragma region CmdLineStuff
            for (int i = 0; i < args.Length; i++)
            {
                Console.WriteLine("{0}", args[i]);
            }
            foreach (string arg in args)
            {
                Console.WriteLine(arg);
            }
            string[] apiargs = Environment.GetCommandLineArgs();//this will give the executable name and path too
            int exitCode = Environment.ExitCode;
            foreach (string arg in apiargs)
            {
                Console.WriteLine(arg);

            }
            Console.WriteLine("Exit Code {0}", exitCode);
            string myString = string.Format("11 in hexa is {0:x}", 11);
            System.Windows.MessageBox.Show(myString);

#pragma endregion CmdLineStuff
            ImmutableStrings();
            Console.ReadLine();
        }

我使用了#pragma region。但是我得到了CS1633:无法识别的#pragma指令警告。所以我认为C#编译器不能识别这个Pragma,因为在C ++中它工作得很好。在C#中是否有任何等效的pragma?

1 个答案:

答案 0 :(得分:6)

只是

#region CmdLineStuff
......
#endregion CmdLineStuff

docs could be found here,此处有C# Preprocessor directives

的完整文档