Skip to content

Tuple and extension methods #16159

@alrz

Description

@alrz
using System;
using System.Linq;
using System.Collections.Generic;
static class C
{
    static IEnumerable<(T, U)> AsEnumerable<T, U>(
        this (IEnumerable<T> xs, IEnumerable<U> ys) source)
	=> source.xs.Zip(source.ys, (x, y) => (x, y));

    static void Main()
    {
        foreach(var (x, y) in AsEnumerable((new int[1], new byte[2]))) // OK
        {          
        }      

        foreach(var (x, y) in (new int[1], new byte[2]).AsEnumerable()) // ERROR; needs cast
        {    
        }  
    }   
}

In fact, an extension GetEnumerator should be sufficient without the explicit call.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions