我有一个大型 for 循环(最大 30k 迭代),它似乎一直在减慢速度:
为了获得一点性能,我从一个foreach循环切换到另一个循环,并尝试了发布配置,但我在这个问题for中找不到任何其他适用于我的内容。循环位于异步方法中
为什么循环速度变慢?可以避免吗?
for(int iter = 0; iter < LargeList1.Count; iter++)
{
var cl_from = LargeList1[iter];
if(LargeList2.Any(cl => cl.str.Contains(cl_from.str)))
{
DateTime dt1 = //last write time of a file
DateTime dt2 = //last write time of a different file
if(DateTime.Compare(dt1, dt2) > 0)
{
try
{
CopyFile(//Kernel32 CopyFile a file overwrite);
globals.fileX++;
} …Run Code Online (Sandbox Code Playgroud) 基于这个问题:如何在数据集上运行查询?
我正在尝试从我的数据集中查询数据表,其中文本包含字符串,类似于String.Contains方法或sql LIKE运算符.
这是我到目前为止所尝试的:
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataTable tbl = globals.UserDataSet.Tables[0];
DataRow[] tempDataRows = tbl.Select("USER_ID Like " + textBox1.Text + " OR THE_NAME Like " + textBox1.Text);
}
Run Code Online (Sandbox Code Playgroud)
这给出了System.Data.SyntaxError错误.
是否可以在数据表中查询包含子字符串的文本?有没有更好的方法呢?
我有一个类列表,其中包含事件名称,时间戳和持续时间(时间跨度).有许多重复的事件名称.我想通过事件名称对它们进行合并,并添加它们的持续时间并保留最早的时间戳,除非事件具有某个名称.即,删除重复的事件名称,添加类似事件名称的持续时间,并保持偶数名称的最早时间戳.
有没有更好的方法呢?可能与Linq?
这是我尝试过的,似乎没有正确合并(仍然有重复,但更少)
班级:
public class eventRecords
{
public DateTime TimeStamp { get; set; }
public string Event { get; set; }
public TimeSpan Duration { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的尝试:
// allEventList is already sorted by TimeStamp, so my thinking is adding
// the first occurrence of an event to newList will keep the earliest
// TimeStamp in eventRecrods for that event
// Also - the duplicates are almost all consecutive in allEventList
var newList = new List<eventRecords>();
for …Run Code Online (Sandbox Code Playgroud)