using System.Collections.Generic;
using System.Globalization;
public class SwiftCodeInfo
public string Country {get; set;}
public string SwiftCode {get; set;}
public string BranchCode {get; set;}
public string Country {get; set;}
public string SwiftCode {get; set;}
public List<string> BranchCodes {get; set;}
public static void Main()
var swiftCodeInfo = new List<SwiftCodeInfo>();
swiftCodeInfo.Add(new SwiftCodeInfo{Country ="USA", SwiftCode ="ABCDEFGH", BranchCode="101"});
swiftCodeInfo.Add(new SwiftCodeInfo{Country ="USA", SwiftCode ="ABCDEFGH", BranchCode="102"});
swiftCodeInfo.Add(new SwiftCodeInfo{Country ="USA", SwiftCode ="ABCDEFGH", BranchCode="103"});
swiftCodeInfo.Add(new SwiftCodeInfo{Country ="USA", SwiftCode ="XYZABCDEF", BranchCode="104"});
swiftCodeInfo.Add(new SwiftCodeInfo{Country ="USA", SwiftCode ="XYZABCDEF", BranchCode="105"});
swiftCodeInfo.Add(new SwiftCodeInfo{Country ="IND", SwiftCode ="ABCDEFGH", BranchCode="106"});
var result = swiftCodeInfo.GroupBy(l => new { l.Country, l.SwiftCode })
.Select(g => new BranchCode {
SwiftCode = g.Key.SwiftCode,
BranchCodes = g.Select(i => i.BranchCode).ToList()
foreach(var item in result)
Console.WriteLine(item.Country+" "+item.SwiftCode+" "+ string.Join(",",item.BranchCodes));