在一个列表中的一个列表的列表项目没有被显示在控制台列表、控制台、项目、列表中

2023-09-06 11:25:50 作者:俄们还有约定

第三的foreach 语句告诉我,它无法转换 System.Collections.Generic.IEnumerable<字符串> 字符串。编号CTAF显示,则显示nomClient但不显示numCompte。我该如何解决这个问题?

下面是code:

 公共静态无效generateCTAF(字符串pathXml,串outputPDF)
{
            名单< FichierCTAF> FC =新的名单,其中,FichierCTAF>();

            FC = getXmlFCtaf(pathXml);

            的foreach(在FC FichierCTAF F)
            {
                 Console.WriteLine(ID CTAF:{0},f.IdFichierCtaf);

                的foreach(字符串nomClient在f.Clients.Select(Y => y.NomClient))
                {
                     Console.WriteLine(喃客户:{0},nomClient);
                     的foreach(在f.Clients.Select(Y =&GT串idCompte; y.ComptesClient.Select(Z => z.NumCompte)))
                        Console.WriteLine(民孔特:{0} \ N,idCompte);
                }
            }
}
 

解决方案

 公共静态无效generateCTAF(字符串pathXml,串outputPDF)
{
    //不要初始化与空单FC变量
    名单< FichierCTAF> FC = getXmlFCtaf(pathXml);

    的foreach(在FC FichierCTAF F)
    {
        Console.WriteLine(ID CTAF:{0},f.IdFichierCtaf);

        的foreach(在f.Clients VAR客户端)//选择客户端在这里
        {
             //显示当前客户的喃
             Console.WriteLine(喃客户:{0},client.NomClient);

             //枚举当前客户的审计院的客户
             的foreach(在client.ComptesClient VAR comptesClient))
               Console.WriteLine(民孔特:{0} \ N,comptesClient.NumCompte);
        }
    }
}
 
Excel中对数据设置有效性,为什么总是出现 列表源必须是划定分界后的数据列表,或是对单一行或一列的引用

请注意:你有错误,因为 f.Clients.Select(Y => y.ComptesClient.Select(Z => z.NumCompte))返回序列字符串>>将字符串序列,即的IEnumerable< IEnumerable的&LT 。所以,当你试图枚举该查询的结果,你会得到类型的项目的IEnumerable<字符串> ,而不是简单的字符串

在你的codde的另一个问题是,你已经选择了所有ComptesClient˚F。但是,你应该只加载与当前客户端的数据。

The third foreach statement tells me that it can not convert System.Collections.Generic.IEnumerable<string> to String. ID CTAF is displayed, nomClient is displayed but numCompte is not displayed. How can I solve this?

Here is the code :

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}", f.IdFichierCtaf);

                foreach(string nomClient in f.Clients.Select(y => y.NomClient))
                {
                     Console.WriteLine(" Nom Client : {0}", nomClient);
                     foreach (string idCompte in f.Clients.Select(y => y.ComptesClient.Select(z => z.NumCompte)))
                        Console.WriteLine(" Num Compte : {0}\n", idCompte);
                }
            }
}

解决方案

public static void generateCTAF(string pathXml, string outputPDF)
{
    // do not initialize fc variable with empty list
    List<FichierCTAF> fc = getXmlFCtaf(pathXml); 

    foreach (FichierCTAF f in fc)
    {
        Console.WriteLine("ID CTAF : {0}", f.IdFichierCtaf);

        foreach(var client in f.Clients) // select client here
        {
             // display Nom of current client
             Console.WriteLine(" Nom Client : {0}", client.NomClient);

             // enumerate comptes clients of current client
             foreach (var comptesClient in client.ComptesClient))
               Console.WriteLine(" Num Compte : {0}\n", comptesClient.NumCompte);
        }
    }
}

NOTE: You have error, because f.Clients.Select(y => y.ComptesClient.Select(z => z.NumCompte)) returns sequence of string sequences, i.e. IEnumerable<IEnumerable<string>>. So, when you are trying to enumerate results of this query, you will get items of type IEnumerable<string> instead of simple string.

Another issue in your codde is that you have selected all ComptesClient of f. But you should load only data related to current client.