In .Net/C# I have a class that’s derived from List. When I try to use the FindNextIndex member of that derived class, I get compile errors like below.
Error 3 Argument 1: cannot convert from ‘method group’ to ‘System.Predicate’
Error 2 The best overloaded method match for ‘System.Collections.Generic.List.FindIndex(System.Predicate)’ has some invalid arguments
Some simplified code is below.
class CTileBag:List<int>
{
...
}
Then later I try to use it in another class
CTileBag c = new CTileBag();
int idx = c.FindIndex(IsSwamp);
And IsSwamp is defined in the class I’m using CTile bag in as
private static bool IsSwamp(TerrainType type)
{
if (type == TerrainType.TT_FUNGUS_SWAMP)
return true;
return false;
}
Your predicate takes a
TerrainType, but your list is aList<int>. The predicate type depends on the list type. It sounds like your tile bag should actually be aList<TerrainType>, at which point it should work.However:
List<int>. Prefer composition over inheritance – I suspect it would be better to make your tile bag type contain aList<T>.C, and make your enum values just PascalCased, likeFungusSwampinstead ofTT_FUNGUS_SWAMP.Your method body can be simplified to just: