输出多个列表的最佳方式是什么?

问题描述:

我正在准备一份报告,我需要对系统中的每个用户进行分类。有大约15K用户。输出多个列表的最佳方式是什么?

因此,我正在通过每个用户,检查他们的各种条件,并根据条件为每个用户分配一个列表。

大约有8-9个列表,这意味着系统中有大约8-9个类别的用户。

现在我需要以一些易于理解的格式报告这些用户。我正在考虑一个CSV文件,其中列将表示这些8-9类别,并且在每个列标题下,我将拥有该列表中的用户。

我可以将所有这些列表写入一个CSV文件,然后它们会一个显示在另一个下面。我不知道如何以表格的形式编写它们,以便阅读和理解。

E.g.让我们考虑我有三类用户。

category1: abc, def, ghi 
category2: lmn, opq, rst 
category3: uvw, xyz, adf 

所以我的输出应该象下面这样:

category1  category2  category3 
abc    lmn    uvw 
def    opq    rst 
uvw    xyz    adf 

我接受其他的建议,以及关于如何我可以输出一个简单的结果,以理解的格式。

+0

将用户在不止一个列表? – yamen

+0

理想情况下,用户不应出现在多个列表中。但是,尽管重叠的可能性很小。 – aspnetdeveloper

对于出口数据的目的,或在数据库中存储只能使用一种格式:

user category 
user1 category1 
user1 category2 
user2 category1 
user2 category2 

Excel和其他报告平台可以将此数据旋转至所需的格式 - 比如

user category1 category2 category3 
user1 x   x 
user2 x      x 

如果您将在Excel中使用这些CSV,我相信您现在的格式是理想的。

对于输出结果;关于像这样的内容:

// Get categories with all users in it 
// and get max count in a category across all categories 
List<List<Category>> categories = GetCategoriesWithUsers(); 
int maxUsersInCategory = categories.Max(x => x.Count); 

using (StreamWriter writer = new StreamWriter("output.csv") 
{ 
    // Loop through each user per category 
    for (int userCount = 0; userCount < maxUseresInCategory; userCount++) 
    { 
     string outputLine = string.Empty; 

     // Loop through each category 
     foreach(List<Category> category in categories) 
     { 
      // If category end isn't reached, add user 
      if (category.Length > userCount) 
      { 
       outputLine += category[userCount]; 
      } 

      outputLine += ","; 
     } 

     outputLine = outputLine.Remove(outputLine.Length - 1); 
     writer.WriteLine(outputLine); 
    } 
}