This is a migrated thread and some comments may be shown as answers.

How to convert For loop to LINQ

2 Answers 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Deekshith
Top achievements
Rank 1
Deekshith asked on 09 Apr 2014, 05:00 AM
Hi Please Help me to Convert bellow Code Snippet to LINQ

foreach (RadComboBoxItem item in rdComboNames.Items)
                {
 
                    CheckBox chk = (CheckBox)item.FindControl("chk1");
                    if (i == 0)
                    {
                        checkedText += "Names:";
                    }
                    else if (chk.Checked)
                    {
                        checkedText += item.Text + ", ";
                    }
                    i++;
                }

2 Answers, 1 is accepted

Sort by
0
Krishnaprabhuraja
Top achievements
Rank 1
answered on 09 Apr 2014, 06:32 AM
Hello,

Try this:
checkedText = string.Concat("Names: ", string.Join(", ",
            rdComboNames.Items.Skip(1)
                .Where(x => x.Checked)
                .Select(x => ((CheckBox) x.FindControl("chk1")).Text)
                .ToArray()));


Thanks,
Krishna Raja
0
Deekshith
Top achievements
Rank 1
answered on 10 Apr 2014, 04:37 AM
Thank you. .
Tags
General Discussions
Asked by
Deekshith
Top achievements
Rank 1
Answers by
Krishnaprabhuraja
Top achievements
Rank 1
Deekshith
Top achievements
Rank 1
Share this question
or