admin管理员组文章数量:1122846
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.
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.
Share Improve this question asked Nov 22, 2024 at 11:59 David RahlDavid Rahl 815 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 5No.
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.
本文标签: In Ccan you declare multiple function arguments as a single typeStack Overflow
版权声明:本文标题:In C#, can you declare multiple function arguments as a single type? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303889a1932039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Bar1, Bar2, Bar3
are related they should probably have their own type. If they are unrelated it seem weird to use the same type declaration. – JonasH Commented Nov 22, 2024 at 12:17params
keyword allowing a varying number of parameters to be passed at the call site:public void Foo(params int[] bar) { }
or use tuples:public void Foo((int, int, int) foo, (string, string, string) bar) { }
– Olivier Jacot-Descombes Commented Nov 22, 2024 at 13:49