Reputation: 26547
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?
Upvotes: 8
Views: 18156
Reputation: 158349
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);
Upvotes: 14
Reputation: 3434
In C# you do not need to specify anything in particular to break a line into several on-screen lines.
So a method which would look like this in vb:
sub someMethod(param1 as String, _
param2 as Integer, _
param3 as Boolean)
doSomething()
end sub
Will look like this in C#
public void someMethod(string param1,
int param2,
bool param3) {
doSomething();
}
Upvotes: 7
Reputation: 1502296
If you mean in terms of the layout, there are various options, such as:
Option 1:
public void Foo(int first, int second,
int third, int fourth,
int fifth, int sixth)
Option 2:
public void Foo(int first, int second,
int third, int fourth,
int fifth, int sixth)
Option 3:
public void Foo(
int first, int second,
int third, int fourth,
int fifth, int sixth)
Option 4:
public void Foo
(int first, int second,
int third, int fourth,
int fifth, int sixth)
Personally I like option 1, but it has two disadvantages:
Failing that, I'd generally go with option 2 or 3. Option 4 looks pretty ugly to me.
Upvotes: 6
Reputation: 28617
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.
Upvotes: 21
Reputation: 116528
public void Foo(object Parameter0, object Parameter1,
object Parameter2, object Parameter3,
object Parameter4, object Parameter5)
{
//do stuff
}
6 parameters / 3 lines = 2 parameters per line? Although I'd say that looks a little funny because there's extra room on each line.
Note that in C#, you can just use a line break - nothing fancy needed (VB's "_
" for instance).
Upvotes: 2
Reputation: 41276
You can break the lines using the ENTER key, towards the right side of your keyboard.
Upvotes: 11
Reputation: 18800
What do you mean? like this?
public void MyMethod(int Parameter1, string Parameter2
, long Parameter3, float Parameter4
, double Parameter5, char Parameter6)
{
//Method Functionality
}
Upvotes: 2
Reputation: 4503
If I understood rightly what you are saying then,,,
public void myMethod ( type parameter1,
type parameter2,
.
.
type parameterN)
{
.
.
.
}
Upvotes: 1