Click here to Skip to main content
15,902,447 members
Home / Discussions / C#
   

C#

 
QuestionHelp ThreadPools/Threads Pin
peterzorbas6-Sep-06 13:30
peterzorbas6-Sep-06 13:30 
QuestionCopy and Past shortcuts stop working when derived form shown non-modally. Pin
Vengeance6-Sep-06 12:50
Vengeance6-Sep-06 12:50 
Questiongeneric inherited class Pin
daveroberge6-Sep-06 9:33
daveroberge6-Sep-06 9:33 
AnswerRe: generic inherited class Pin
Nader Elshehabi6-Sep-06 10:17
Nader Elshehabi6-Sep-06 10:17 
GeneralRe: generic inherited class Pin
daveroberge6-Sep-06 10:46
daveroberge6-Sep-06 10:46 
QuestionRe: generic inherited class Pin
Nader Elshehabi6-Sep-06 11:30
Nader Elshehabi6-Sep-06 11:30 
AnswerRe: generic inherited class Pin
daveroberge6-Sep-06 14:04
daveroberge6-Sep-06 14:04 
AnswerRe: generic inherited class Pin
Nader Elshehabi7-Sep-06 1:59
Nader Elshehabi7-Sep-06 1:59 
Hello

Gotcha!! Now your problem is clear. Here it is: -Watch carefully for generic types-

1- First you declare an object of type I1<c1> you name it oTest2
2- Then you call GetG2()
3- In the method you declare another object of type g2<c2> with the name oG2
Are following me??

Now the problem is that the definition of class g2 is that you inherit it from class g1<c2> -notice the c2 here!!-. So in the base class g1 which has the interface I1 the generic type is c2!! So by default the generic type of I1 -which is the interface of g1 and has the same generic type- is c2, not c1!! That's why when you try to return oG2 and cast it to interface I1<c1> it doesn't work!! It implements interface I1<c2> not I1<c1>. I hope now you see your problem now.

Suggested solutions -among many other solutions of course-.
1- Return type I1<c2> instead
private I1<c2> GetG2()
{
g2<c2> oG2 = new g2<c2>();
oG2.Add(new c2());
return (I1<c2>)oG2;
}

I1<c2> oTest2 = GetG2();
This will preserve your inheritance structure.

OR
Change your inheritance to implement I1<c1> interface in G2

class g2<t> : g1<c2>, I1<c1> where t : c2
{
public override void Add(c2 a)
{
a.sVal2 = "testmodified2";
base.Add(a);
}

public void Add(c1 a)
{
//Do something
}
}

I hope this helps!!

Regards
GeneralRe: generic inherited class Pin
daveroberge7-Sep-06 3:07
daveroberge7-Sep-06 3:07 
GeneralRe: generic inherited class Pin
Nader Elshehabi7-Sep-06 9:04
Nader Elshehabi7-Sep-06 9:04 
GeneralRe: generic inherited class Pin
daveroberge7-Sep-06 10:53
daveroberge7-Sep-06 10:53 
GeneralRe: generic inherited class Pin
Nader Elshehabi7-Sep-06 11:26
Nader Elshehabi7-Sep-06 11:26 
GeneralRe: generic inherited class Pin
daveroberge7-Sep-06 14:31
daveroberge7-Sep-06 14:31 
AnswerRe: generic inherited class Pin
Ed.Poore6-Sep-06 12:01
Ed.Poore6-Sep-06 12:01 
GeneralRe: generic inherited class Pin
daveroberge6-Sep-06 14:09
daveroberge6-Sep-06 14:09 
GeneralRe: generic inherited class Pin
Ed.Poore6-Sep-06 18:38
Ed.Poore6-Sep-06 18:38 
GeneralRe: generic inherited class Pin
daveroberge7-Sep-06 2:54
daveroberge7-Sep-06 2:54 
QuestionPlacing description into a class/method??? Pin
Goalie356-Sep-06 8:55
Goalie356-Sep-06 8:55 
AnswerRe: Placing description into a class/method??? Pin
Nader Elshehabi6-Sep-06 9:13
Nader Elshehabi6-Sep-06 9:13 
GeneralRe: Placing description into a class/method??? Pin
Goalie356-Sep-06 9:31
Goalie356-Sep-06 9:31 
GeneralRe: Placing description into a class/method??? Pin
Nader Elshehabi6-Sep-06 9:46
Nader Elshehabi6-Sep-06 9:46 
JokeRe: Placing description into a class/method??? Pin
Not Active6-Sep-06 9:56
mentorNot Active6-Sep-06 9:56 
JokeRe: Placing description into a class/method??? Pin
Nader Elshehabi6-Sep-06 10:36
Nader Elshehabi6-Sep-06 10:36 
QuestionHTML to MS Word or RTF Pin
Nadia Monalisa6-Sep-06 8:27
Nadia Monalisa6-Sep-06 8:27 
AnswerRe: HTML to MS Word or RTF Pin
led mike6-Sep-06 10:18
led mike6-Sep-06 10:18 

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.