SO72467007

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
					
public class Program
{
	public static void Main()
	{
		A();
		B();
	}
	
	public static void A()
	{
		var myList = new List<string>{ "AB", "CD", "EF", "GK" };
		var result = from a in myList from b in myList where a != b select a+b;
		var resultStr = string.Join(",", result);
		Console.WriteLine(resultStr);
	}
	
	public static void B()
	{
		var myList = new List<string> { "AB", "CD", "EF", "GK" };
		var result = myList.SelectMany(a => myList.Where(b => b != a).Select(b => a + b));
		var resultStr = string.Join(",", result);
		Console.WriteLine(resultStr);
	}
}
;