params-keyword Questions

2

Solved

public class SomeClass { public SomeClass(SomeType[] elements) { } public SomeClass(params SomeType[] elements) { } } I printed this code and got CS0111 error. I'm surprised, are S...
Mickelson asked 19/9, 2022 at 14:0

5

Solved

When I'm trying to use params in an Action delegate... private Action<string, params object[]> WriteToLogCallBack; I received this design time error: Invalid token 'params' in class, st...
Vergne asked 30/10, 2010 at 16:36

4

Solved

I am trying to combine the C# 5.0 Caller Information along with the C# params keyword. The intention is to create a wrapper for a logging framework, and we want the logger to format the text like S...
Aguish asked 3/11, 2014 at 16:51

2

Solved

There are a number of examples in the .NET framework where there are multiple overloads for a method, some of which use a specific number of parameters followed by a final "catch all" where the par...
Carmeliacarmelina asked 5/9, 2014 at 15:39

3

Solved

I've recently started exploring lambda expressions, and a question came to mind. Say I have a function that requires an indeterminate number of parameters. I would use the params keyword to m...
Tod asked 26/6, 2012 at 20:1

2

I have a method like this: public void Foo(params string[] args) { bar(args[0]); bar(args[1]); } The new requirements lead to a change like this: public void Foo(string baz, params string[] ...
Philender asked 5/12, 2013 at 13:0

2

Solved

I'm aware that a params modifier (which turns in one parameter of array type into a so-called "parameter array") is specifically not a part of the method signature. Now consider this example: clas...

5

Solved

As you know C# supports variadic methods through the params keyword: int Add(params int[] xs) { return xs.Sum(); } Which can then be called with any number of arguments you like: Add(1); Add(1...
Gardal asked 20/2, 2013 at 15:27

6

Solved

I would like to do something like that: public string GetMessage(params object otherValues[]) { return String.Format(this.Message, this.FirstValue, otherValues); } So, I would like to repass an...
Oniskey asked 8/5, 2012 at 17:41

5

Solved

As I understand it, params is just syntactic sugar that "under the hood" simply gives you an array of the type you specify. First, when would you use this? Second, why would you use it instead of...
Marv asked 28/4, 2011 at 17:35

3

Solved

In Common Lisp you can do this: (defun foo (bar &key baz quux) (list bar baz quux)) (foo 1 :quux 3 :baz 2) ; => (1 2 3) Clojure doesn't have keyword arguments. One alternative is this: ...
Presbyterian asked 4/4, 2009 at 22:39

1

Solved

I just noticed a strange behavior with overload resolution. Assume that I have the following method : public static void DoSomething<T>(IEnumerable<T> items) { // Whatever // For d...

3

Solved

In C#, I am trying to use <see cref="blah"/> to reference a method signature that contains the params keyword. I know this converts the parameter list to an array, but I can't even figure out...
Oneeyed asked 17/4, 2009 at 16:20

7

Solved

Background I have a container class which uses vector<std::string> internally. I have provided a method AddChar(std::string) to this wrapper class which does a push_back() to the internal ve...
Oscoumbrian asked 2/3, 2009 at 3:44

5

Solved

Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string version = Versioner.GetBuildAndDotNetVersions(); string callingModule = StackC...
Intaglio asked 10/10, 2008 at 19:19
1

© 2022 - 2024 — McMap. All rights reserved.