Monday, 6 February 2012

Can I use Interface as a parameter?

Yes,we can use interface as a parameter.my all the examples i disscuse based on Array class. now also take
Array class.
class ArrayList : IList, ICollection, IEnumerable, ICloneable
{
         public ArrayList(ICollection c);
}

So ArrayList takes an object of type which implements ICollection interface.

here SortedList object also ArrayList accepts as a parameter.why because SortedList also implements ICollection Interface.
but Reverse is not Possible.why because SortedList is key/value Collection type.so SortedList can't take ArrayList object as a parameter.

ArrayList :IList   -------> implements IList
                 and
SortedList:IDictionary --->implements IDictionary interfaces.
so sortedList takes another SortedList object as a Paramter.
ok we will see few more Interface later sections.

No comments:

Post a Comment