C # Variable Length Arguments

This may not be possible, but here goes:

I want to create a structure where I can determine the number of arguments when declaring.

For example, now I use:

KeyValuePair<T, T>

but KeyValuePair can only use the key and value.

Is it possible to do something like:

CustomValues<T, {T, {..}}>

I think this is not possible, but maybe I just don't know enough C #. I am also open to smart workarounds,

thanks

+5
source share
4 answers

No, this is not possible, as shown Func<T>, Func<T, TResult>, Func<T1, T2, TResult>etc.

+3
source

But your KVP value type can also be generic:

KeyValuePair<T, List<U,V>>

OR

KeyValuePair<T, KeyValuePair<U,V>>
+1
source

public class CustomClass
    {
     KeyValuePair<T , KeyValuePair<T, V>> setOfArguments;
     public CustomClass(KeyValuePair<T, KeyValuePair<T, V>> _setOfArguments)
      {
        setOfArguments = _setOfArguments;
      }       
    }
+1

?

public void UseParams(params KeyValuePair<String, String>[] list) {
     ...
}
0

All Articles