C#匿名类能实现接口吗?
public interface DummyInterface{ string A { get; } string B { get; }}public class DummySource{ public string A { get; set; } public string C { get; set; } public string D { get; set; }}public class Test{ public void WillThisWork() { var source = new DummySource[0]; var values = from value in source select new { A = value.A, B = value.C + "_" + value.D }; DoSomethingWithDummyInterface(values); } public void DoSomethingWithDummyInterface(IEnumerable<DummyInterface> values) { foreach (var value in values) { Console.WriteLine("A = '{0}', B = '{1}'", value.A, value.B); } }}
守候你守候我
九州编程