Search code examples
c#.netlistlinq-to-xml

item in a list of a list is not beeing displayed


enter image description here

it shows me the idfichier, and the nomclient shows system.linq.enumerable... I guess it is showing the type of nomclient.

public static void generateCTAF(string pathXml, string outputPDF)
        {
            List<FichierCTAF> fc = new List<FichierCTAF>();

            fc = getXmlFCtaf(pathXml);

            foreach (FichierCTAF f in fc)
            {
                Console.WriteLine("ID CTAF : {0} \n Nom Client : {1}\n \n", f.IdFichierCtaf, f.Clients.Select(y => y.NomClient ));
            }

        }

How can I display that? the picture displays the result that i got


Solution

  • You see that strange System.Linq.Enumerable+WhereSelectListIterator because it's ToString() representation of list iterator, which is returned by f.Clients.Select(y => y.NomClient) query.

    If you need to display all NomClient values, I suggest you to build concatenated string of them:

    public static void generateCTAF(string pathXml, string outputPDF)
    {
        List<FichierCTAF> fc = getXmlFCtaf(pathXml);
    
        foreach (FichierCTAF f in fc)
        {
            Console.WriteLine("ID CTAF : {0}\n Nom Client : {1}\n\n", 
               f.IdFichierCtaf, 
               String.Join(", ", f.Clients.Select(y => y.NomClient)));
        }
    }
    

    Or you can enumerate NomClients values and print each on its own line:

    public static void generateCTAF(string pathXml, string outputPDF)
    {
        List<FichierCTAF> fc = getXmlFCtaf(pathXml);
    
        foreach (FichierCTAF f in fc)
        {
            Console.WriteLine("ID CTAF : {0}", f.IdFichierCtaf);
    
            foreach(string nomClient in f.Clients.Select(y => y.NomClient))
                Console.WriteLine(" Nom Client : {0}", nomClient);
        }
    }