如何在.NET /foo/bar.txt中将绝对或相对URI路径(例如)转换为(分段)相应的相对文件系统路径(例如foo\bar.txt)?
我的程序不是ASP.NET应用程序.
为什么,对于"必须从A继承"的类P的类型参数T的通用约束,第一次调用成功但第二次调用失败,注释中详细说明了类型转换错误:
abstract class A { }
static class S
{
public static void DoFirst(A argument) { }
public static void DoSecond(ICollection<A> argument) { }
}
static class P<T>
where T : A, new()
{
static void Do()
{
S.DoFirst(new T()); // this call is OK
S.DoSecond(new List<T>()); // this call won't compile with:
/* cannot convert from 'System.Collections.Generic.List<T>'
to 'System.Collections.Generic.ICollection<A>' */
}
}
Run Code Online (Sandbox Code Playgroud)
如果不是通用约束保证List<T> 是真的ICollection<A>?