如何防止Visual Studio弄乱我的代码缩进?

时间:2011-05-17 08:14:12

标签: visual-studio-2010

Visual Basic 2010会自动更改我的代码缩进::

public void fetchWebserviceCounters()  {
    csv = new StringBuilder();
    try  {
       Category = new PerformanceCounterCategory("Web Service");
       foreach (String instance in Category.GetInstanceNames())  {
          counters = Category.GetCounters(instance);
          foreach (PerformanceCounter counter in counters)  {
              if (counter.CounterName == "Total Bytes Sent" | counter.CounterName == "Total Bytes Recieved") {
                 csv.Append(counter.CounterName + ",");
                 csv.Append(counter.NextValue().ToString() + ", ");
              }
          }
       }
   }
   catch (Exception e) {
            Console.WriteLine(e.Message);
   }
   Console.Write(csv.ToString());

}

到这个

public void fetchWebserviceCounters()
    {
        csv = new StringBuilder();
        try
        {
            Category = new PerformanceCounterCategory("Web Service");
            foreach (String instance in Category.GetInstanceNames())
            {
                counters = Category.GetCounters(instance);
                foreach (PerformanceCounter counter in counters)
                {
                    if (counter.CounterName == "Total Bytes Sent" | counter.CounterName == "Total Bytes Recieved")
                    {
                        csv.Append(counter.CounterName + ",");
                        csv.Append(counter.NextValue().ToString() + ", ");
                    }
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        Console.Write(csv.ToString());
    }

如何阻止Visual Basic对我的代码执行此操作

1 个答案:

答案 0 :(得分:3)

如果您将C#传递给Visual Basic编辑器,则期望它变得混乱。

VS中有许多文本格式选项:工具|选项|文字编辑器|语言|格式化。

这些程度取决于语言,并包括有关何时自动重新格式化代码的选项。