我有一个通用的方法
bool DoesEntityExist<T>(Guid guid, ITransaction transaction) where T : IGloballyIdentifiable;
Run Code Online (Sandbox Code Playgroud)
如何以下列方式使用该方法:
Type t = entity.GetType();
DoesEntityExist<t>(entityGuid, transaction);
Run Code Online (Sandbox Code Playgroud)
我一直收到愚蠢的编译错误:
找不到类型或命名空间名称't'(您是否缺少using指令或程序集引用?)
DoesEntityExist<MyType>(entityGuid, transaction);
Run Code Online (Sandbox Code Playgroud)
完美的工作,但我不想使用if指令每次调用具有单独类型名称的方法.
是否可以实现以下代码?我知道它不起作用,但我想知道是否有解决方法?
Type k = typeof(double);
List<k> lst = new List<k>();
Run Code Online (Sandbox Code Playgroud) 我有一个字符串变量,表示自定义类的名称.例:
string s = "Customer";
Run Code Online (Sandbox Code Playgroud)
我需要创建一个客户的arraylist.所以,所需的语法是:
List<Customer> cust = new ..
Run Code Online (Sandbox Code Playgroud)
如何转换字符串s以便能够在运行时创建此arraylist?
我创建这样的泛型类:
public class Sample<T> where T : class
{
public DoSomething();
}
Run Code Online (Sandbox Code Playgroud)
然后我创建新类:
public class Sample2
{
Sample<Sample2> obj=new Sample<Sample2>();
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能使用下面的代码Sample在Sample2类中创建类的实例?
Sample<typeof<this>> obj=new Sample<typeof<this>>();
Run Code Online (Sandbox Code Playgroud)