给定以下结构:
public struct Foo<T>
{
public Foo(T obj) { }
public static implicit operator Foo<T>(T input)
{
return new Foo<T>(input);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码编译:
private Foo<ICloneable> MakeFoo()
{
string c = "hello";
return c; // Success: string is ICloneable, ICloneable implicitly converted to Foo<ICloneable>
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码没有编译 - 为什么?
private Foo<ICloneable> MakeFoo()
{
ICloneable c = "hello";
return c; // Error: ICloneable can't be converted to Foo<ICloneable>. WTH?
}
Run Code Online (Sandbox Code Playgroud) 我有两节课:
public class Row : Dictionary<string,string> {}
public class Table : List<Row> {}
Run Code Online (Sandbox Code Playgroud)
在应该返回Table类型的对象的方法中,我尝试使用Where -Statement过滤Table类型的对象,并在过滤后返回此对象.
Table table = new Table();
table = tableObject.Where(x => x.Value.Equals("")).ToList();
return table;
Run Code Online (Sandbox Code Playgroud)
我的问题是生成的IEnumerable的演员表.
附加信息:无法将'System.Collections.Generic.List`1 [Row]'类型的对象强制转换为'Table'类型.
如何从IEnumerable中返回Table类型的对象?