Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable length arguments c#

Tags:

This is probably not possible, but here goes:

I want to create a struct where I can define the amount of arguments at declaration.

for example, now I am using:

KeyValuePair<T, T>

but KeyValuePair can only ever take a Key , and a Value .

Is it possible to make something like:

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

I think this isn't possible, but maybe I just don't know enough C#. I'm also open to clever workarounds,

Thank you

like image 550
Theofanis Pantelides Avatar asked Feb 09 '10 11:02

Theofanis Pantelides


People also ask

What is variable length arguments in C?

Variable length argument is a feature that allows a function to receive any number of arguments. There are situations where we want a function to handle variable number of arguments according to requirement. 1) Sum of given numbers. 2) Minimum of given numbers.

What are variable length arguments give an example?

Variable-length arguments, abbreviated as varargs, are defined as arguments that can also accept an unlimited amount of data as input. The developer doesn't have to wrap the data in a list or any other sequence while using them. Let's understand the concept with the help of an example.

What is a variable length argument list?

Variable-length argument lists, makes it possible to write a method that accepts any number of arguments when it is called. For example, suppose we need to write a method named sum that can accept any number of int values and then return the sum of those values.


1 Answers

No, this isn't possible, as showcased by Func<T>, Func<T, TResult>, Func<T1, T2, TResult>, etc.

like image 85
Mark Seemann Avatar answered Nov 15 '22 04:11

Mark Seemann