c++

C# – How to break lines for a method definition with many parameters in C#

c++

In c#, when we are writing a method which gets for example 6 parameters, and we want to break the parameters in 3 lines, how could we break the lines?

Best Solution

In C# you can break the lines after any parameter name (either before of after the comma). Stylecop (the Microsoft coding style guideline checker) suggests either all parameters on one line, or one per line - nothing in between. Like so:

public void Method(int param1, int param2, int param3, int param4, int param5, int param6){}public void Method(    int param1,    int param2,    int param3,    int param4,    int param5,    int param6){}

But, there is no requirement to follow these guidelines, you can do whatever suits your internal style.