최근에 나는이 문제에 직접 직면했으며 List 대신 IEnumerable을 사용하면 문제가 해결된다는 것을 알게되었습니다. 상당히 실망한 문제 였지만 문제의 원인을 찾았 으면 이치에 맞았습니다. 당신이 더 많은 답을 얻기 위해서 C#을 태그를 추가 할 수 있습니다
using System.Collections.Generic;
namespace InheritList.Test
{
public interface IItem
{
string theItem;
}
public interface IList
{
IEnumerable<IItem> theItems; // previously has as list... didn't work.
// when I changed to IEnumerable, it worked.
public IItem returnTheItem();
public IEnumerable<IItem> returnTheItemsAsList();
}
public class Item : IItem
{
string theItem;
}
public class List : IList
{
public IEnumerable<IItem> theItems; // List here didn't work - changed to IEnumerable
public List()
{
this.theItems = returnTheItemsAsList();
}
public IItem returnTheItem()
{
return new Item();
}
public IEnumerable<IItem> returnTheItemsAsList()
{
var newList = new List<Item>();
return newList;
}
}
}
:
는 여기에 내가 해결책을 찾기 위해 사용하는 테스트 코드입니다. – jgauffin