Click here to Skip to main content
15,906,708 members
Home / Discussions / C#
   

C#

 
AnswerRe: GetWindowRect incorrect Pin
Alan N4-Aug-09 13:54
Alan N4-Aug-09 13:54 
AnswerRe: GetWindowRect incorrect Pin
Luc Pattyn4-Aug-09 14:39
sitebuilderLuc Pattyn4-Aug-09 14:39 
AnswerRe: GetWindowRect incorrect Pin
ChicagoBobT2-Aug-10 4:24
ChicagoBobT2-Aug-10 4:24 
QuestionBulleted List: Which control to be used? Pin
DotNetXenon4-Aug-09 11:20
DotNetXenon4-Aug-09 11:20 
AnswerRe: Bulleted List: Which control to be used? Pin
Not Active4-Aug-09 13:19
mentorNot Active4-Aug-09 13:19 
GeneralRe: Bulleted List: Which control to be used? Pin
DotNetXenon5-Aug-09 6:00
DotNetXenon5-Aug-09 6:00 
GeneralRe: Bulleted List: Which control to be used? Pin
Not Active5-Aug-09 7:05
mentorNot Active5-Aug-09 7:05 
QuestionDLL references: Console vs Windows Forms Pin
banderas204-Aug-09 11:05
banderas204-Aug-09 11:05 
AnswerRe: DLL references: Console vs Windows Forms Pin
stancrm4-Aug-09 20:28
stancrm4-Aug-09 20:28 
GeneralRe: DLL references: Console vs Windows Forms Pin
banderas204-Aug-09 21:28
banderas204-Aug-09 21:28 
QuestionSimple problem with brackets [modified] Pin
Amangang4-Aug-09 10:33
Amangang4-Aug-09 10:33 
AnswerRe: Simple problem with brackets Pin
VengefulSakhmet4-Aug-09 10:53
VengefulSakhmet4-Aug-09 10:53 
QuestionRe: Simple problem with brackets Pin
Amangang4-Aug-09 22:49
Amangang4-Aug-09 22:49 
AnswerRe: Simple problem with brackets Pin
Henry Minute4-Aug-09 22:54
Henry Minute4-Aug-09 22:54 
GeneralRe: Simple problem with brackets Pin
Amangang4-Aug-09 22:59
Amangang4-Aug-09 22:59 
GeneralRe: Simple problem with brackets Pin
Amangang5-Aug-09 2:15
Amangang5-Aug-09 2:15 
GeneralRe: Simple problem with brackets Pin
VengefulSakhmet5-Aug-09 3:34
VengefulSakhmet5-Aug-09 3:34 
GeneralRe: Simple problem with brackets Pin
Amangang5-Aug-09 3:41
Amangang5-Aug-09 3:41 
QuestionCasting List<concreteclass> to IList<interfaceconcreclass></interfaceconcreclass></concreteclass> Pin
Ubirajara Mendes4-Aug-09 8:49
Ubirajara Mendes4-Aug-09 8:49 
AnswerRe: Casting List to IList Pin
Adam Maras4-Aug-09 9:31
Adam Maras4-Aug-09 9:31 
GeneralRe: Casting List to IList Pin
Ubirajara Mendes5-Aug-09 9:03
Ubirajara Mendes5-Aug-09 9:03 
AnswerRe: Casting List to IList Pin
Adam Maras5-Aug-09 11:13
Adam Maras5-Aug-09 11:13 
Ahh... I see the problem now.

Your problem is one related to covariance and contravariance[^]. Let me show you an example:

public interface IMyClass { }

public class MyClass : IMyClass { }
public class MyOtherClass : IMyClass { }
In this example, you have an interface, and two classes that implement said interface. Now, you've created a generic list of your first class type:
List<MyClass> listMyClass = new List<MyClass>();
Let's say, for the sake of this argument you weren't getting that cast error, and you could cast to a generic list of your interface type:
List<IMyClass> listIMyClass = ( List<IMyClass> )listMyClass;

Now, while only one list exists (because your cast just changed the type of the reference, not the contents of the list) you have created a reference that would allow you to add other objects that implement IMyClass to that list. Think about this:
listMyClass.Add( new MyOtherObject() );  // obviously won't work, MyObject (the list type)
                                         // and MyOtherObject (the type being added) are incompatible

listIMyClass.Add( new MyOtherObject() ); // seems like it should work, because you're adding an object
                                         // that implements IMyClass... but that list you're referencing
                                         // has a generic type of MyClass, NOT IMyClass.

The problem isn't that you're casting a List<> to an IList<>, it's that you're trying to cast from a list with one generic parameter type to another.

Adam Maras | Software Developer
Microsoft Certified Professional Developer

GeneralRe: Casting List to IList Pin
Ubirajara Mendes6-Aug-09 8:50
Ubirajara Mendes6-Aug-09 8:50 
Questiondrag n drop images Pin
strife194-Aug-09 7:39
strife194-Aug-09 7:39 
AnswerRe: drag n drop images Pin
Abhijit Jana4-Aug-09 8:08
professionalAbhijit Jana4-Aug-09 8:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.