Search code examples
c#functiontypesargumentsdeclaration

In C#, can you declare multiple function arguments as a single type?


In Pascal, you can declare multiple function arguments as a single type:

procedure TMyClass.Foo(Bar1, Bar2, Bar3 : string; Bar4, Bar5, Bar6 : Integer);

I always enjoyed this because it prevented needless repetition of type declarations. I know in C#, you can declare multiple variables as a single type:

int foo, bar;

But that doesn't appear to work for C# function arguments:

// Compiler doesn't like this because it expects types for all three arguments
public void Foo(int bar1, bar2, bar3) { }

Does C# have a way to shorthand the declaration of multiple arguments with a single type, or is there some reason it's been rejected? I can't seem to find much information on it, I just keep finding information on multiple-type arguments, which is not what I'm looking for.


Solution

  • No.

    I guess I need more words... "No it doesn't, and is unlikely to ever do so". Reasons: because there hasn't been a compelling enough reason to add it.