什么类型的C#Generic类参数不能? [英] What type can't C# Generic class parameter be?

查看:105
本文介绍了什么类型的C#Generic类参数不能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道C#泛型类不能作为参数

1.静态类

  public   static   class  StaticClass 
{...}

...
GenericClass< StaticClass> obj = new GenericClass< StaticClass>();
...





2.指针(在不安全模式下)

 ... 
GenericClass< int *> obj = new GenericClass< int *>();
...





什么类型的通用类参数不能?

解决方案

最后,我找到了它!!!

它是动态类。

动态类不能是Generic类的参数。



谈到动态课时,我的意思是这个=>



  / *  在装配中加载。 * /  
moduleAssembly = Assembly.LoadFile(fileName);

/ * 获取此程序集中的类类型。 * /
类型type = moduleAssembly.GetTypes();

/ * 创建新实例* /
Activator。的CreateInstance(类型);


I know that C# generic class CAN'T take as a parameter
1. static class

public static class StaticClass
{...}

...
GenericClass<StaticClass> obj= new GenericClass<StaticClass>();
...



2. pointer( in unsafe mode )

...
GenericClass<int*> obj = new GenericClass<int*>();
...



What type else generic class parameter can't be?

解决方案

Finally, I found it!!!
It is dynamic class.
Dynamic class can't be parameter of Generic class.

When talking about dynamic class, I mean this =>

/* Load in the assembly. */
 moduleAssembly = Assembly.LoadFile(fileName);

  /* Get the types of classes that are in this assembly. */
  Type type = moduleAssembly.GetTypes();

/* Create a new instance */
Activator.CreateInstance(type);


这篇关于什么类型的C#Generic类参数不能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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