如何返回通用抽象类? [英] How to return generic abstract class ?

查看:69
本文介绍了如何返回通用抽象类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!


我有这样的事情:

Hi there!

I have something like this:

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号

推荐答案

发布时请使用CODE标签,它使您的代码更容易阅读。


这样的事情:
Please use CODE tags when posting, it makes your code much easier to read.

How about something like this:
展开 | 选择 | Wrap | 行号


@vekipeki


感谢您的回复,

对不起我是新手,下次我会使用CODE标签。我的问题是关于
@vekipeki
Thank You for response,
Sorry I am newbie here, next time I will use CODE tags. My question concerns
展开 | 选择 | Wrap | 行号


这里需要注意的重要事项是Class1.Instance的类型为Class1,而Class2.Instance的类型为Class2 。因为它们都是静态的并且没有在任何接口或父抽象类中定义,所以对于C#编译器它们是完全不同的。


你告诉编译器T应该从BaseClass派生出来< T> ;但是你没有告诉他T是Class1或Class2,所以它不想允许它。


如果您的代码编译没有错误会发生什么,以及有人写道:
The important thing to notice here is that Class1.Instance is of type Class1, while Class2.Instance is of type Class2. Since they are both static and are not defined in any interface or parent abstract class, for C# compiler they are completely different.

You are telling compiler that T should be derived from BaseClass<T>, but you are not telling him that T is Class1 or Class2, so it doesn''t want to allow that.

What would happen if your code would compile without errors, and somebody wrote this:
展开 | 选择 < span class =codeDivider> | Wrap | 行号


这篇关于如何返回通用抽象类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆