泛型约束可以使用在方法中吗?
public abstract class DataAccess<TDataTable, TDataContext> : IDisposable
where TDataTable : class, new()
where TDataContext : DataContext, new()
{
}
///如何在某个方法中使用?
public abstract class DataAccess {
public void NewData<TDataTable, TDataContext>()
where TDataTable : class, new()
where TDataContext : DataContext, new()
{}
}
------解决方案--------------------
可以,类似的
C# code
public static void OpTest<T>(T s, T t) where T : class
{
System.Console.WriteLine(s == t);
}
static void Main()
{
string s1 = "foo";
System.Text.StringBuilder sb = new System.Text.StringBuilder("foo");
string s2 = sb.ToString();
OpTest<string>(s1, s2);
}