programming-examples/c-sharp/Linq/C# Sharp to generate a Cartesian Product of three sets.cs

25 lines
920 B
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
using System;
using System.Linq;
using System.Collections.Generic;
class LinqExercise24
{
public static void Main(string[] args)
{
char[] charset1 = { 'X', 'Y', 'Z' };
int[] numset1 = { 1, 2, 3 };
string[] colorset1 = { "Green", "Orange" };
Console.Write("\nLINQ : Generate a Cartesian Product of three sets : ");
Console.Write("\n----------------------------------------------------\n");
var cartesianProduct = from letter in charset1
from number in numset1
from colour in colorset1
select new { letter, number, colour };
Console.Write("The Cartesian Product are : \n");
foreach (var ProductList in cartesianProduct)
{
Console.WriteLine(ProductList);
}
Console.ReadLine();
}
}