class Program
{
public struct scoreInformation
{
public int number;
public int time;
public int counter;
}
static void Main(string[] args)
{
scoreInformation[] scoreStatistic = new scoreInformation[]
{
new scoreInformation(){ number=1, time=2, counter=3 },
new scoreInformation(){ number=2, time=2, counter=3 },
new scoreInformation(){ number=3, time=2, counter=3 },
}; var result = scoreStatistic.FirstOrDefault(x => x.number == 1);
Console.WriteLine(result.number);//输出1
}
}
{
public struct scoreInformation
{
public int number;
public int time;
public int counter;
}
static void Main(string[] args)
{
scoreInformation[] scoreStatistic = new scoreInformation[]
{
new scoreInformation(){ number=1, time=2, counter=3 },
new scoreInformation(){ number=2, time=2, counter=3 },
new scoreInformation(){ number=3, time=2, counter=3 },
}; var result = scoreStatistic.FirstOrDefault(x => x.number == 1);
Console.WriteLine(result.number);//输出1
}
}
2:遍历集合,object as 变量类型,赋值;
L.Add(new scoreInformation() {number=1,time=1,counter=1 })