c#Robust Ling Idea [英] c# Robust Ling Idea
问题描述
我想在下面的颜色表中找到一个处理或一次收到3封邮件的链接。 在下面的颜色表中我有8条记录。将有3个获得,最后获得将只有2个记录。所以我们想要考虑剩余的记录。是否有一个
linq可以处理我想要实现的逻辑。一旦我获得3个批次的记录,我就会对批次做一些事情
颜色表:
ID |  项目
1   |   红色
2   |   蓝色
3   |   绿色
4   |   棕色
5   |  purple
6   |  黄色
7   |  orange
8   |  紫
pianoboyCoder
您好pianoboyCoder,
感谢您发布此处。
根据您的描述,我不确定您存储数据的位置。我以dataTable为例。请 尝试以下代码。
static void Main(string [] args)
{
List< string> item = new List< string>();
DataTable table = GetTable();
foreach(table.Rows中的DataRow行)
{
item.Add(row [" Item"]。ToString());
}
var q = item.Select((v,i)=> new {v,t = i / 3})。GroupBy(p => pt,p => pv) ;
var result = q.Select(g => g.ToList())。ToList(); //这里是你想要的列表。
}
static DataTable GetTable()
{
DataTable table = new DataTable(); //新数据表
table.Columns.Add(" ID",typeof(int));
table.Columns.Add(" Item",typeof(string));
table.Rows.Add(1," red");
table.Rows.Add(2," blue");
table.Rows.Add(3," green");
table.Rows.Add(4," brown");
table.Rows.Add(5," purple");
table.Rows.Add(6," yellow");
table.Rows.Add(7," yellow");
table.Rows.Add(8,"violet");
返回表; //返回参考。
}
最好的问候,
Wendy
I am trying to come up a link to process or get 3 messages at a time in the color table below. In the color table below I 8 records. There will be 3 gets, the last get will only 2 records. So we want to account for the remaining records. Is there a linq that can handle this logic I am trying to achieve. Once I get the record in batches of 3's I go do something with the batch
Color Table:
ID | Item
1 | red
2 | blue
3 | green
4 | brown
5 | purple
6 | yellow
7 | orange
8 | violet
pianoboyCoder
Hi pianoboyCoder,
Thank you for posting here.
According to your description, I am not sure where you store the data. I use dataTable for example. Please try the following code.
static void Main(string[] args) { List<string> item = new List<string>(); DataTable table = GetTable(); foreach (DataRow row in table.Rows) { item.Add(row["Item"].ToString()); } var q = item.Select((v, i) => new { v, t = i / 3 }).GroupBy(p => p.t, p => p.v); var result = q.Select(g => g.ToList()).ToList();//here is the list you want. } static DataTable GetTable() { DataTable table = new DataTable(); // New data table. table.Columns.Add("ID", typeof(int)); table.Columns.Add("Item", typeof(string)); table.Rows.Add(1, "red"); table.Rows.Add(2, "blue"); table.Rows.Add(3, "green"); table.Rows.Add(4, "brown"); table.Rows.Add(5, "purple"); table.Rows.Add(6, "yellow"); table.Rows.Add(7, "yellow"); table.Rows.Add(8, "violet"); return table; // Return reference. }
Best Regards,
Wendy
这篇关于c#Robust Ling Idea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!