여기 학생.목록 < > 사전 < K,List< > 내부> (C#)
현재 C# 프로젝트 작업. 나는 카드 < 카드>를 만들고, < 사전 문자열, 목록 < 카드>를 생성해야합니다.
목록은 독립적으로 생성되고 사전은 카드 모음을 보유합니다. 컬렉션에서 카드를 추가하거나 제거 할 수 있습니다.
컬렉션에 카드를 추가하는 데 문제가 있습니다. 사용자 입력에서 목록의 색인 번호를 얻었으므로 색인에 따라 사전의 값을 간단히 업데이트하려고합니다.
오류를 발생시키는 행이 여기에 있습니다. 이 오류는 System.Collections.Generic.List < filename.CardClass> '
나는 내 인생에 대한
알아낼 수없는 것을 그 수단과 방법을 암시 적 유형'< filename.CardClass> ' 로 변환 할 수 없습니다 입니다 내가Dictionary<string, List<Card>>
및을 입력한다
_collections
가정
public void AddToCollection()
{
PrintValuesCollections<string, List<Card>>(_collections);
Console.WriteLine("Type in the name of the collection to add a card to:");
string input = Console.ReadLine();
bool found = _collections.ContainsKey(input);
if (found)
{
Console.WriteLine("List of current cards to choose from:");
for (int i = 0; i < _cards.Count; i++)
{
Console.WriteLine("Index number:\r\n"+i+"Card Info:\r\n"+_cards[i]+"\n");
}
Console.WriteLine("Type in the index of the card from the list to add to the collection:");
string cardSelection = Console.ReadLine();
int cardSelectionIndex = 0;
while (!int.TryParse(cardSelection, out cardSelectionIndex))
{
Console.Write("Please enter a number from the list above: ");
input = Console.ReadLine();
}
_collections[input] = _cards[cardSelectionIndex];
_cards.RemoveAt(cardSelectionIndex);
}
else
Console.WriteLine("Collection name not found.");
}
'_collections [입력] .Add (_cards [cardSelectionIndex]);'? – flakes
확실치 않지만 새로운 고유 키를 추가하지 않습니까? 전에 언급 했어야 할 것은 이미 생성 된 키를 가지고 있으며 단순히 사용자의 키 입력을 기반으로 값을 업데이트하려고합니다. –