Click here to Skip to main content
16,004,653 members

Comments by The_Unknown_Member (Top 42 by date)

The_Unknown_Member 9-Apr-18 8:27am View    
@Maciej Los Yes I know this.
The_Unknown_Member 9-Apr-18 7:07am View    
I meant that it won't work because List of T doesn't support covariance (classes can't support covariance + it will break the type safety in this case). The question is mostly about the second part

IList<derived> derived = new List<derived>();
IList <base /> basee = derived;


Specifically this line:
IList <base /> basee = derived;

Here I am allowed to cast the derived to IList<base /> (of course it will fail in runtime but here i'm talking about compile time). How did the compiler determine that
the derived list can be casted to IList? Does it care about the generic parameters? Or it just cares about the inheritance tree of List<t> so in this case IList<t> is implemented by List<t> hence the compiler allows me to cast my list to IList without caring about the generics. Is this the case?
The_Unknown_Member 1-Apr-18 7:12am View    
But the reference variable that points to a list of dogs is the interface "IList<dog>" so I am supposed to do an explicit cast to assign the list to the IEnumerable<animal> reference. But actually it works??
See this example:
static void Main()
{

IAnimal a = new Dog();
Bark(a);

}

static void Bark(Dog d)
{
Console.WriteLine("Baau baaau :@@@");
}


"Bark(a);" this code won't work unless I cast the argument explicitly to Dog.
The_Unknown_Member 1-Apr-18 5:59am View    
Is this behavior only happening with ternary operators?
The_Unknown_Member 23-Mar-18 15:23pm View    
One last question:How does FindAll not accept anything other than a boolean value. I want to know this particular detail of the implementation. It's a generic method but it works only with boolean values and when I try to return an int for example the compiler gives error: "Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type".

The delegate is generic too.