Jump to content

Recommended Posts

Posted

Given a setup like this:

 

public interface ISomething

{

***public void SomeMethod();

}

 

public class Bob : ISomething

{

***...

}

 

public class Jenny : ISomething

{

***...

}

 

public class SomethingCollection where T : ISomething

{

...

}

 

public SomethingCollection GimmeSomeSomethings(SomeClause)

{

***switch( SomeClause )

***{

******case One:

******return SomethingCollection;

 

******case Two:

******return SomethingCollection;

***}

}

 

Why doesn't this work, and how could it be made to?

 

main()

{

***SomethingCollection = (SomethingCollection)GimmeSomeSomethings(One);

}

 

(Can we assume that any typographical errors or minor issues are only because I'm writing this to illustrate the problem.)

 

I get a "cannot convert type SomethingCollection to SomethingCollection" error. I've been trying to read up on Covariance and Contravariance, so feel free to jargon me to death and I'll just have to cope.

 

Because if it doesn't work, I may have to go back and change a stack of someone's code... (whoop-ti-doo)

 

[edit: don't spare me, if it's simply that despite Bob*being a subclass*of (or "smaller than" if you prefer")*ISomething, SomethingCollection isn't a subclass of (smaller than) SomethingCollection. Then I need to know definitively.]

 

More...

 

View All Our Microsft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...