C# 使用条件筛选arraylist
我有一个ArrayList,上面有多个项目,每个项目都是一个字符串,除以逗号“loglogs”,前三个项目是本地化(Destin、lat和long)。我需要根据按钮工具提示中的本地化(基于这三个参数)或编程文本,在按钮中插入这些日志的字符串。我有所有的按钮创建,但我必须添加字符串,但有更多的日志比按钮,所以 我需要将ArrayList“过滤”到另一个ArrayList中,根据这三个初始坐标对其进行过滤,我想创建另一个ArrayList,但在ArrayList的前三个元素中添加相同的字符串。这样,我将把“loglogs”合并成另一个“logscondensed”,所有的“本地化”都是唯一的,这样我就可以将这个部分添加到我的按钮和索引创建中C# 使用条件筛选arraylist,c#,visual-studio,arraylist,C#,Visual Studio,Arraylist,我有一个ArrayList,上面有多个项目,每个项目都是一个字符串,除以逗号“loglogs”,前三个项目是本地化(Destin、lat和long)。我需要根据按钮工具提示中的本地化(基于这三个参数)或编程文本,在按钮中插入这些日志的字符串。我有所有的按钮创建,但我必须添加字符串,但有更多的日志比按钮,所以 我需要将ArrayList“过滤”到另一个ArrayList中,根据这三个初始坐标对其进行过滤,我想创建另一个ArrayList,但在ArrayList的前三个元素中添加相同的字符串。这样,
foreach (String log in logslogs)
{
String[] colContent = log.Split(','); //splited the content with commas
Loglog log = new Loglog(); //Loglog is a class of logs with information in specific columns
log.Destin = colContent[0];
log.Lat = Convert.ToChar(colContent[1]);
log.Long = colContent[2];
log.Barcode = colContent[6];
log.Source = colContent[7];
log.SampleName = colContent[9];
AllLogs.Add(log);
我需要从具有1000个成员的logslog传递到具有较少项的ArrayList,其中基于前三个项具有相同位置的项作为一个项追加
如果你知道如何正确地编码,这是一件很容易的事(不是我的情况)。万分感谢你把这篇文章读出来,更感谢那些试图帮助你的人
最好的,我有解决办法!,可能不会赢得任何清洁竞赛,但它满足了我的需要!。我创建一个索引,根据三个坐标(Destin、Long和Lat)对项目进行过滤比较。如果它们相同,我将删除最后一个项目,并将追加的行放在最后一个位置,依此类推
int c = 0; //Just to go the first time
//We create an index to compare the former with the "actual"
//log in every loop of the "foreach"
String IndiceDestin0 = string.Empty;
String IndiceLat0 = string.Empty;
String IndiceLong0 = string.Empty;
String IndiceDestin1;
String IndiceLat1;
String IndiceLong1;
foreach (String log in logslogs)
{
String[] LongContent = log.Split(',');
Loglog log = new Loglog();
log.Destin = LongContent[0];
log.Lat = Convert.ToChar(LongContent[1]);
log.Long = LongContent[2];
log.Barcode = LongContent[6];
log.Source = LongContent[7];
log.DestDestinBarcode = LongContent[8];
log.SampleName = LongContent[9];
AllLogs.Add(log);
//This only works once, the first time because we don't have a "former" data to compare we have to bypass the comparison
if (c == 0)
{
IndiceDestin0 = LongContent[0];
IndiceLat0 = LongContent[1];
IndiceLong0 = LongContent[2];
c++;
}
else
{
IndiceDestin1 = LongContent[0];
IndiceLat1 = LongContent[1];
IndiceLong1 = LongContent[2];
if (IndiceDestin0.Equals(IndiceDestin1) && IndiceLat0.Equals(IndiceLat1) && IndiceLong0.Equals(IndiceLong1))
{
int last = logsToButtons.Count - 1;
string oldLog = logsToButtons[last].ToString();
string appendedLog = oldLog + log;
//We remove the last "single" log to add the aggregated log
logsToButtons.RemoveAt(last);
logsToButtons.Add(appendedLog);
}
else
{
logsToButtons.Add(log);
}
IndiceDestin0 = IndiceDestin1;
IndiceLat0 = IndiceLat1;
IndiceLong0 = IndiceLong1;
c++;
}
}
我得到了一个较短版本的阵列,但附加在一起的那些有相同的坐标,谢谢大家的帮助,我知道这是混乱的,但它的工作
最好的,我有解决办法!,可能不会赢得任何清洁竞赛,但它满足了我的需要!。我创建一个索引,根据三个坐标(Destin、Long和Lat)对项目进行过滤比较。如果它们相同,我将删除最后一个项目,并将追加的行放在最后一个位置,依此类推
int c = 0; //Just to go the first time
//We create an index to compare the former with the "actual"
//log in every loop of the "foreach"
String IndiceDestin0 = string.Empty;
String IndiceLat0 = string.Empty;
String IndiceLong0 = string.Empty;
String IndiceDestin1;
String IndiceLat1;
String IndiceLong1;
foreach (String log in logslogs)
{
String[] LongContent = log.Split(',');
Loglog log = new Loglog();
log.Destin = LongContent[0];
log.Lat = Convert.ToChar(LongContent[1]);
log.Long = LongContent[2];
log.Barcode = LongContent[6];
log.Source = LongContent[7];
log.DestDestinBarcode = LongContent[8];
log.SampleName = LongContent[9];
AllLogs.Add(log);
//This only works once, the first time because we don't have a "former" data to compare we have to bypass the comparison
if (c == 0)
{
IndiceDestin0 = LongContent[0];
IndiceLat0 = LongContent[1];
IndiceLong0 = LongContent[2];
c++;
}
else
{
IndiceDestin1 = LongContent[0];
IndiceLat1 = LongContent[1];
IndiceLong1 = LongContent[2];
if (IndiceDestin0.Equals(IndiceDestin1) && IndiceLat0.Equals(IndiceLat1) && IndiceLong0.Equals(IndiceLong1))
{
int last = logsToButtons.Count - 1;
string oldLog = logsToButtons[last].ToString();
string appendedLog = oldLog + log;
//We remove the last "single" log to add the aggregated log
logsToButtons.RemoveAt(last);
logsToButtons.Add(appendedLog);
}
else
{
logsToButtons.Add(log);
}
IndiceDestin0 = IndiceDestin1;
IndiceLat0 = IndiceLat1;
IndiceLong0 = IndiceLong1;
c++;
}
}
我得到了一个较短版本的阵列,但附加在一起的那些有相同的坐标,谢谢大家的帮助,我知道这是混乱的,但它的工作
最好的