运行 VS 时出现“检测到无法访问的代码”错误。我在这两行收到错误:
MoveListItems(listBox1,listBox2)
和ReplaceListItems(listBox1,listBox2)
任何帮助表示赞赏!
下面的代码:
private string CreateNewEntry(string current)
{
var indexIn = current.LastIndexOf("Time In : "); // Get the last index of the word "in"
var indexOut = current.LastIndexOf("Time Out : "); // Get the last index of the word out
if (indexOut > indexIn)
{
return current + " "+"Time In : "; // if the last "out" comes after the last "in"
ReplaceListBoxItems(listBox1,listBox2);
}
else
{
// If the last "in" comes after the last "out"
return current + " " +"Time Out : ";
MoveListBoxItems(listBox1,listBox2);
}
}
private void MoveListBoxItems(ListBox source, ListBox destination)
{
ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
foreach (var item in sourceItems)
{
destination.Items.Add(item);
}
while (source.SelectedItems.Count > 0)
{
source.Items.Remove(source.SelectedItems[0]);
}
}