C# - Is it possible to extend an existing built-in class with a new Interface?

You want to use List.AsReadOnly. msdn.microsoft.com/en-us/library/e78dcd7...).aspx.

IList has no AsReadOnly method. – Miriam Nov 25 '09 at 18:27 1 @Miriam: If it's an IList in C# 3, you can use list.ToList().AsReadOnly(). – TrueWill Nov 25 '09 at 19:05 3 You can always do a IList readOnlyList = new ReadOnlyCollection(mutableList); which creates an access wrapper for the original list (changes to the original list will be reflected in the readonly list).

– Lucero Nov 25 '09 at 19:08 @Lucero ReadOnlyCollection works just for List but what if I want to use a Dictionary? – mrbamboo Dec 2 '09 at 16:24 @mrbamboo: blackwasp.co. Uk/ReadOnlyDictionary.aspx.

Easily found on Google. – Paul Sonier Dec 2 '09 at 18:19.

Yes, I believe that would work. Give it a shot, and let us know how it works :D.

The answer is no: IList does not implement IMyOwnInterface so you can't cast it. IList list = ... MyLittleMethod((IMyOwnInterface)list) // Compiler errror here In this case you can use ReadOnlycollection: IList list = ... MyLittleMethod(new ReadOnlyCollection(list)).

With interfaces, it's basically only possible through inheritance or with some proxy stuff (either explicit with an adapter class, via a RealProxy implementation, or with a library to do things like that, such as LinFu). However, out of the box you can use delegates to do late-binding for single methods with matching signature.

Very complicated, especially for a beginner. – Miriam Nov 25 '09 at 18:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions