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?
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.
I guess you can just simply add the line breaks:
private void SomeMethod(int param1, int param2,
int param3, int param4,
int param5, int param6)
{
// do something
}
In C# (unlike VB.NET - at least up to now; this will change in VS2010, check "Implicit Line Continuation" about half way down on the page) you can introduce line breaks in the code pretty much anywhere. You don't need to specify that the code statement continues on the next line; that is taken care of by the syntax.
If you have a method declared as my sample above, this does not set up any requirements on how you call it. The following examples are all valid:
SomeMethod(1, 2, 3, 4, 5, 6);
SomeMethod(1, 2, 3, 4, 5,
6);
SomeMethod(1
, 2, 3, 4
, 5, 6);
You can break the lines using the ENTER key, towards the right side of your keyboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With