T
tshad
I have some code where I build a small list from a larger list and then use
this list to test with.
For example:
List<FieldName> fieldNameList = fieldNames.FindAll(delegate(FieldName
fieldName)
{ return fieldName.XMLFieldName == (string)r["tagName"]; });
The fieldName collection would be about 300 items long and the resulting
fieldNameList may be about 20.
I would then go through my smaller list of 20 to compare against a string.
My question is whether this is more efficient than:
***************************************
List<FieldName> fieldNameList = new List<FieldName>();
foreach (FieldName fn in fieldNames)
{
if (fieldName.XMLFieldName == (string)r["tagName"])
fieldNameList.Add(fieldName);
}
******************************************
In both cases, I end up with a collection of FieldNames in my new
fieldNameList.
Is the delegate way faster?
It seems to do exactly the same thing. Someone before said it was a better
way to do (less coding for one thing).
In a related question:
Is using the delegate *.Find faster or more efficient than going through a
loop like the one above?
Thanks,
Tom
this list to test with.
For example:
List<FieldName> fieldNameList = fieldNames.FindAll(delegate(FieldName
fieldName)
{ return fieldName.XMLFieldName == (string)r["tagName"]; });
The fieldName collection would be about 300 items long and the resulting
fieldNameList may be about 20.
I would then go through my smaller list of 20 to compare against a string.
My question is whether this is more efficient than:
***************************************
List<FieldName> fieldNameList = new List<FieldName>();
foreach (FieldName fn in fieldNames)
{
if (fieldName.XMLFieldName == (string)r["tagName"])
fieldNameList.Add(fieldName);
}
******************************************
In both cases, I end up with a collection of FieldNames in my new
fieldNameList.
Is the delegate way faster?
It seems to do exactly the same thing. Someone before said it was a better
way to do (less coding for one thing).
In a related question:
Is using the delegate *.Find faster or more efficient than going through a
loop like the one above?
Thanks,
Tom