Windows phone 8 ';foreach&x27;对表中的所有行执行操作的步骤
我有以下类和数据上下文结构Windows phone 8 ';foreach&x27;对表中的所有行执行操作的步骤,windows-phone-8,foreach,sql-server-ce,Windows Phone 8,Foreach,Sql Server Ce,我有以下类和数据上下文结构 public class Accounts { public string AccountName { get; set; } public string SecretKey { get; set; } } class MyDataContext : DataContext { public MyDataContext (string ConnectionString) : base(ConnectionString) {
public class Accounts
{
public string AccountName { get; set; }
public string SecretKey { get; set; }
}
class MyDataContext : DataContext
{
public MyDataContext (string ConnectionString) : base(ConnectionString)
{
}
public Table<Accounts> AllAccounts
{
get
{
return this.GetTable<Accounts>();
}
}
}
首先,如果不键入变量,就不能执行
foreach
循环。对于表
,必须对其行执行foreach
:
Table t = new Table();
foreach (TableRow tr in t.Rows)
{
//enter code here
}
一旦你有了行,你就可以得到数据了
其次,您不能键入表
。您可以使用键入的列表
(例如类的列表
)并执行相同的操作,但使用列表
中设置的类型:
List<Accounts> AccountList = new List<Accounts>();
foreach (Accounts a in AccountList)
{
//enter code here
}
List AccountList=新列表();
foreach(帐户列表中的帐户a)
{
//在这里输入代码
}
从列表中获得对象后,可以对其执行所需的任何功能
List<Accounts> AccountList = new List<Accounts>();
foreach (Accounts a in AccountList)
{
//enter code here
}