我正在創建一個應用程序,其工作是生成兩個列表並按需顯示它們。以及每秒鐘更新值。替換列表中最古老的值?
我需要以這種方式更新列表,以便列表中最老的值先被替換。我會怎麼做?下面是我的代碼當前狀態。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data_Collector
{
//What is needed?
//Need to generate a list of both metric values, and imperial values.
//Need to be able to display a list
public class IMeasuringDevice_Helper
{
private int limit; //Limits the list size.
private float RNDouble;
public void MetricValueGenerator()
{
limit = limit + 1;
Console.WriteLine("Limit Level = " + limit);
if (limit <= 10)
{
List<float> MetricValueGenerated = new List<float>();
Random rnd = new Random();
float rndINT = rnd.Next(1, 10);
RNDouble = rndINT/10;
Console.WriteLine(RNDouble);
MetricValueGenerated.Add(RNDouble);
}
else
{
Console.WriteLine("limit reached");
}
}
public void ImperialValueGenerator()
{
//TODO
}
}
}
聽起來像你需要一個FIFO數據結構或一個循環隊列。 –
正如@ Pierre-LucPineault所提到的,FIFO結構是有意義的,比如[queue](https://msdn.microsoft.com/en-us/library/7977ey2c(v = vs.110).aspx) – Rob