tags:

views:

26

answers:

1
 public struct Items
{
    public string Id;
    public string Name;

}

   public Items[] _items = null;

if (_items.Contains("Table"))
                {
                    // i need to check the structure and need to return correponding id
                }

and am having a list of variables in my structure variable...
i need to search a Name in the structure(_items) and i want to return the Corresponding Id.

how to do this,

+1  A: 
foreach (Items item in _items)
{
    if (item.Name.Contains("search string"))
    {
        return item.Id;
    }
}
Svisstack
It throws some explicit conversion error,
deep
@deep: where???
Svisstack
at this line if(item.Name.Contains("search string")) , its does not going into loop, it throws error, while checking the condition
deep
@deep: paste your source code, i may think your collection is not declarated or you doing it wrong.
Svisstack
Thanks Sivss, Got the ans by the following code.the error due to empty collection. got solved, thanks Ans: for (int i = 0; i < _items.Length; i += 1) // for each file { if (_items[i].Name == "Table") { string a = _items[i].Id.ToString(); } }
deep