Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Visual Studio 2010 automatically changes indentation of my code from this ::

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());

}

to this

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());
    }

How can i prevent Visual Studio from Doing this to My code

share|improve this question
    
You say "Visual Basic" but the code sample is C#, do you mean "Visual Studio"? –  Binary Worrier May 17 '11 at 8:44
    
yes yes my bad i mean Visual studio. i have edited accordingly. now pls give your input –  Wildling May 17 '11 at 9:16
    
eek, I know its a matter of style, but personally I hate the top style its feels to Java-script like. But I'll happly use that style when writing Javascript! :) –  Darknight May 17 '11 at 9:58
    
but master wayne would you pls care to give some alternatives ? P.S. i like the top style cos it takes less lines and (for me) makes code easier to read –  Wildling May 17 '11 at 10:26
2  
This question appears to be off-topic because it is about a programming tool (IDE), which would normally belong on Stack Overflow, but is too old to migrate. –  MichaelT yesterday

1 Answer 1

up vote 5 down vote accepted

Normally you want visual studio to do formatting so that you can have consistency, you just have to change your settings to fit your style (or change your style to fit your settings :)

In C# you can change a number of formatting settings but it seems vb doesnt have that option, I think you have to get something like resharper for that. You can turn it off though by going to Options > Text Editor > Basic > VB Specific and unchecking "pretty listing"

EDIT

Ooops, saw that it wasn't vb, if you go to Options > Text Editor > c# > Formatting > Newlines you have the newline options for formatting

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.