CSharp · Console
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace Sample
{
public class Program
{
public static void Main(string[] args)
{
var lst = new List<Assinante>(){new Assinante
{
City= "BAURU",
Num= 112,
ClientCode= 3123,
Phone= "1412345675"
},
new Assinante
{
City= "BAURU",
Num= 45,
ClientCode= 3123,
Phone= "214464347"
}};
var xml = new XElement("div");
foreach(var city in lst.GroupBy(x=>x.City))
{
var cityXml = new XElement("h2", city.Key);
var cityUl = new XElement("ul");
foreach(var client in city.GroupBy(c=>c.ClientCode))
{
var clientXml = new XElement("li", client.Key);
var clientUl = new XElement("ul");
foreach(var num in client.GroupBy(cl=>cl.Num))
{
var numXml = new XElement("li", num.Key);
var numUl = new XElement("ul");
foreach(var phone in num)
{
numUl.Add(new XElement("li",phone.Phone));
}
clientUl.Add(numXml);
clientUl.Add(numUl);
}
cityUl.Add(clientXml);
cityUl.Add(clientUl);
}
xml.Add(cityXml);
xml.Add(cityUl);
}
Console.WriteLine(xml);
}
private class Assinante
{
public string City;
public int Num;
public int ClientCode;
public string Phone;
}
}
}