ASP.net C# LINQ for 循环
// Load all the links
ArtworkingDataContext dc = new ArtworkingDataContext();
var q = (from Labels in dc.tblArtworkLabels where Labels.templateID == this.ID select new { LabelID = Labels.ID });
// Create labels array
this.Labels = new ArtworkLabel[q.Count()];
for (int i = 0; i < q.Count(); i++)
{
this.Labels[i] = new ArtworkLabel(q.LabelID);
}
q.LabelID 不起作用,我不能真正使用 foreach,因为我必须在每次迭代时调用一个新的 ArtworkLabel。
// Load all the links
ArtworkingDataContext dc = new ArtworkingDataContext();
var q = (from Labels in dc.tblArtworkLabels where Labels.templateID == this.ID select new { LabelID = Labels.ID });
// Create labels array
this.Labels = new ArtworkLabel[q.Count()];
for (int i = 0; i < q.Count(); i++)
{
this.Labels[i] = new ArtworkLabel(q.LabelID);
}
The q.LabelID isn't working, I can't really use a foreach because I have to invoke a new ArtworkLabel on each iteration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可行:
您也可以直接从查询中进行投影:
This would work:
Also you can directly project from your query:
尝试这样:
Try like this:
你可能会这样做,对吧?
You could potentially just do this, right?
您应该能够在一个 linq 语句中完成这一切。
You should be able to do it all in one linq statement.
我最近尝试了这个,一个 linq for 循环..这就是我想出的..
I tried this recently, a linq for loop.. this is what I came up with..