hi everyone, i want to ask, if infos variable inside have a many data, how can i get just 5-6 data ?
foreach (var info in infos)
{
htmlTh = new TableHeaderCell();
htmlTh.Text = info.Name;
htmlTr.Cells.Add(htmlTh);
}

Raja TRank #685 · 3.5K reputationPosted Nov 11, 2015, 8:54 PM EST
Banketeshvar NarayanRank #235 · 10.5K reputationPosted Nov 11, 2015, 8:43 PM EST
You can decide that which data you want to iterate using break and continue.
You can use something like
foreach (var info in infos)
{
if (info != yourequireddata)
continue;
htmlTh = new TableHeaderCell();
htmlTh.Text = info.Name;
htmlTr.Cells.Add(htmlTh);
}
or if you need only 5 data you can use break keyword.
Ekrem TapanRank #1,694 · 900 reputationPosted Nov 11, 2015, 9:02 PM EST
Raja TRank #685 · 3.5K reputationPosted Nov 11, 2015, 9:04 PM EST
Banketeshvar NarayanRank #235 · 10.5K reputationPosted Nov 11, 2015, 9:12 PM EST
You are most Welcome..
But just right now I have seen that you have written that you want the result using LINQ.
you can achieve it by below query
var list = (from t in infos
select t
).Take(5);
Please accept as answer if it helps you.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts