-6

I want to know what is the c in the below source code . can you explain me what is it doing ???

        private void txtFamilytoSearch_TextChanged(object sender, EventArgs e)
    {
        var db = new LINQDataContext();
        if (txtFamilytoSearch.Text == "")
            gvTable.DataSource = db.MyTables;
        else
            gvTable.DataSource = db.MyTables.Where(c => c.Family.Substring(0, txtFamilytoSearch.Text.Length) == txtFamilytoSearch.Text).Select(c => c);

    }

this is some part of C# code in linq tecnology.

thank you ;-)

2 Answers2

2

When you use Linq where, it iterates over every item in the collection and applies the predicate that you provide.

In this case, c represents an individual element in the collection db.MyTables

David Pilkington
  • 13,528
  • 3
  • 41
  • 73
1

It is an identifier for the currently iterated element of your collection. It is the same as if you´d write

var result = new List<T>;  // here T is the actual type of your list 

foreach(var c in db.MyTables) 
{ 
    if (c.Family.Substring(0, txtFamilytoSearch.Text.Length) == txtFamilytoSearch.Text) 
    { 
        result.Add(c); 
    }
}
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111