使用泛型类中的静态方法 [英] Using static method from generic class
本文介绍了使用泛型类中的静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到上述问题.我的代码:
I have problem as above. My code:
public abstract class BaseFactory<T> where T: class
{
protected static dbModelContainer context = new dbModelContainer();
public static int UpdateDataBase_static()
{
return context.SaveChanges();
}
}
我的问题是我怎么打电话
and my question is how can I call
BaseFactory.UpdateDataBase_static();
代替:
BaseFactory<SomeClass>.UpdateDataBase_static();
有什么想法吗?
推荐答案
您不能,因为没有这样的方法.最接近的是具有泛型类继承自的非泛型基数.然后,您可以在那里使用一种不依赖于参数设置类型的方法.
You can't, because there is no such method. The closest is to have a non-generic base that the generic class inherits from. Then you can have a method there that doesn't depend on the parameterising type.
这篇关于使用泛型类中的静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文