Reputation: 1329
I have certain number of objects in a list, I would like to select one object from the list based on the name. I have tried the following code. It doesn't yield any [Enumeration Yielded no results ]. It is bit strange. Could anybody help with this? . My code is below
var tableobj = from table in tableOfObjects
where tableOfObjects.ToString().Contains(objName)
select table;
Here tableOfObjects contains certain number of objects and, objName is to select an object based on the name of the object
Update::::::::::::::::::::::
tableOfObjects contains certain number of class objects it is defined as ListtableOfObjects
Upvotes: 0
Views: 56
Reputation: 1010
try this
var tableobj = from table in tableOfObjects
where table.ToString().Contains(objName)
select table;
Upvotes: 1
Reputation: 7601
you can use the typeOf
for checking object.
var tableobj=tableOfObjects.Where(p=>typeOf(p)==typeOf(obj));
or
var tableobj = from table in tableOfObjects
where table.ToString().Contains(objName)
select table;
Upvotes: 3