I have a class that subclass a generic List. I did it to implement a toJSONString() that I need to call regularly on this kind of list. So my class is something like this:
public class Foos : List<Foo>
{
public string toJSONString()
{
//Do something here
}
}
In another Class i have a method doing this:
public class Bar
{
private Foos m_Foos = new m_Foos();
public Foos filterWith(Query p_query)
{
Foos newList = m_Foos.FindAll(
// Make a test through a delegate
});
return (newList);
}
}
I get this error:
Error CS0266: Cannot implicitly convert type
System.Collections.Generic.List<Foo>' to
Foos'. An explicit conversion exists (are you missing a cast?) (CS0266) (Assembly-CSharp)
The problem is that m_Foos.FindAll(...) return a "List" not a "Foos". Explicit casting doesn't do the trick, because I then have a runtime error.
I have read this post, but it doesn't seem to give an appropriate solution to my problem: C# - Why can I not cast a List<MyObject> to a class that inherits from List<MyObject>?