tags:

views:

67

answers:

2

Hi

From dahlbyk answer to this question : http://stackoverflow.com/questions/4038978/map-two-lists-into-a-dictionary-in-c , Leppie wrote this comment:

Pity there is a need for a Zip method. If only more statically typed languages would support generic variadic parameters, Select would handle this (like map in Scheme). – leppie

What does that mean? (I don't know Scheme) :)

+2  A: 

He means, that if C# would support dynamic number or arguments (variadic, params) which are all of a different generic type, there wouldn't be a need for a Zip method, because it could be covered by Select.

I don't know if this is true, just interpreting the sentence ...

Edit:

I just think that he means a variable number of generic types (which is in fact only useful in combination with a variable number of method arguments), like this:

void Foo<params T>(params T[] args)

Foo(true, 7, "hello");

Just think about the many declarations of Action<...> and Func<...>.

By the way, when you are not sure about a comment, why not simply asking him?

Stefan Steinegger
+1 That would be nice, just like in [C++0x](http://en.wikipedia.org/wiki/C%2B%2B0x#Variadic_templates).
Jordão
+1  A: 

The C# language does in fact support variadic parameters. Here's an example:

using System;

class Program {
    static void Main(string[] args) {
        VariadicExample(__arglist(1));
        VariadicExample(__arglist(1, 2, 3));
        Console.ReadLine();
    }
    static void VariadicExample(__arglist) {
        var iter = new ArgIterator(__arglist);
        int cnt = iter.GetRemainingCount();
        for (int ix = 0; ix < cnt; ++ix) {
            TypedReference arg = iter.GetNextArg();
            Console.WriteLine(TypedReference.ToObject(arg));
        }
    }
}

But don't, use the params keyword instead.

Hans Passant
These are not generic arguments.
Stefan Steinegger