0
我有一个名为X的变量UNIT类型。这个变量每隔几毫秒更新一次。从变量创建唯一值数组
在C#windows窗体应用程序我需要存储此变量的数据。假设第一次暂停= 5,我需要创建一个列表并存储5 然后它变成7然后存储7但是如果再次返回5,忽略5,因为它已经包含在我的列表中
然后我需要从列表中访问这些变量。
我有一个名为X的变量UNIT类型。这个变量每隔几毫秒更新一次。从变量创建唯一值数组
在C#windows窗体应用程序我需要存储此变量的数据。假设第一次暂停= 5,我需要创建一个列表并存储5 然后它变成7然后存储7但是如果再次返回5,忽略5,因为它已经包含在我的列表中
然后我需要从列表中访问这些变量。
Use a set。确保重复内容不被添加的逻辑是内置的。
var numbers = new HashSet<uint>();
numbers.Add(5); // Adds 5, returns true.
numbers.Add(5); // Doesn't add anything, returns false.
List<int> numbers = new List<int>(); // this is the list
int[] numbersArray = new int[] { 99, 98, 92, 97, 95 }; // numbers array
foreach (var num in numbersArray)
{
if (!numbers.Contains(num)) // Check if the number exists
{
numbers.Add(num);// this will only add if the number doesn't exist
}
}
你能后至今你已经尝试了什么? – Rob