Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to use Zip to combines elements from two arrays using Linq in C#

3 Answers

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        string[] people = { "Albus", "Arthur", "Alanna", "Avalon" };
        int[] ages = { 40, 51, 60, 45 };
        
        var result = people.Zip(ages, (p, e) => p + " " + e);
        
        foreach (var pair in result) {
            Console.WriteLine(pair);
        }
    }
}
  
 
 
  
/*
run:
  
Albus 40
Arthur 51
Alanna 60
Avalon 45

*/

 



answered Jul 4, 2023 by avibootz
0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        var arr1 = new[] { 1, 2, 3, 4 };
        var arr2 = new[] { 8, 9, 0, 7 };

        var result = arr1.Zip(arr2, (x, y) => x * y);

        Console.WriteLine(string.Join(", ", result));
    }
}
  
 
 
  
/*
run:
  
8, 18, 0, 28

*/

 



answered Jul 4, 2023 by avibootz
0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        int[] numbers = Enumerable.Range(1, 5).ToArray();
        string[] people = { "Albus", "Arthur", "Alanna", "Avalon" };

        var result = numbers.Zip(people, (n, p) => n + ": " + p);

        foreach (var pair in result) {
            Console.WriteLine(pair);
        }
    }
}
  
 
 
  
/*
run:
  
1: Albus
2: Arthur
3: Alanna
4: Avalon

*/

 



answered Jul 4, 2023 by avibootz

Related questions

1 answer 103 views
1 answer 99 views
1 answer 136 views
2 answers 131 views
1 answer 213 views
213 views asked Mar 10, 2021 by avibootz
1 answer 138 views
...