我有以下课程:
public class players
{
public void LottoDraw(object sender, EventArgs e)
{
var connectionstring = "Server=C;Database=lotto;User Id=lottoadmin;Password=password;";
using (var con = new SqlConnection(connectionstring)) // Create connection with automatic disposal
{
con.Open();
// Create new DataTable
DataTable player = new DataTable();
{
// Create new DataAdapter
using (SqlDataAdapter a = new SqlDataAdapter("SELECT TOP 1 LOTTOID, VAL0, VAL1, VAL2, VAL3, VAL4, VAL5 FROM tblLotto ORDER BY NEWID()", con))
{
// Use DataAdapter to fill DataTable
a.Fill(player);
}
}
}
}
public int val0, val1, val2, val3, val4, val5, val6;
public IEnumerable<int> Numbers
{
get
{
return new[] { val0, val1, val2, val3, val4, val5, val6 };
}
}
}
}
它将从数据库中返回一个随机行,其中包含一些乐透号码。然后这些值将被放入一个集合中。
然后,我想使用一些 Linq 将中奖号码与抽出的号码进行比较。
public void LottoWinners(object sender, EventArgs e)
{
Dictionary<int, int> number = new Dictionary<int, int>();
Random generator = new Random();
while (number.Count < 1)
{
number[generator.Next(1, 49)] = 1;
}
string[] lotto = number.Keys.OrderBy(n => n).Select(s => s.ToString()).ToArray();
var winners = players.
Where(Lotto => Lotto.Players.Numbers.Intersect(lotto).Count() >= 3);
//write some logic to find out who has 3 match numbers
//and assign there ticket to the winners table tblWinners
}
但是我得到一个错误:
“Lotto.players”不包含“Where”的定义
我已经有:using System.Linq;
在我所有的文件中!