I'm converting my cards game to C#
In one case which appears very often I get error
Fehler CS1061 "ItemCollection" enthält keine Definition für "Item", und es konnte keine zugängliche Item-Erweiterungsmethode gefunden werden, die ein erstes Argument vom Typ "ItemCollection" akzeptiert (möglicherweise fehlt eine using-Direktive oder ein Assemblyverweis).
Error CS1061 "ItemCollection" does not contain a definition for "Item" and could not find an accessible item extension method that accepts an initial argument of type "ItemCollection" (a using directive or assembly reference may be missing).
The problem appears for "withBlock.Item(n)"
VB:
<Extension()>
Public Function SelectFirstCardCommonCheck_ALL(hc As HandCards,
Wnd As MainWindow, ByVal CardsPanel As Object,
TrumpID As Integer, LeadSuitID As Integer) As PlayingCard
Dim sHand As String
Dim FindCard As PlayingCard
Dim ACP As New AutoCardPlay(Wnd.sk.trumpCard, Wnd)
sHand = hc.GetHandString
With CardsPanel.Items
sHand = String.Empty
If .Count > 0 Then
For n = 0 To .Count - 1
If Wnd.iTricks > 5 Then
If NonTrumpCards(hc, TrumpID) IsNot Nothing Then
If NonTrumpCards(hc, TrumpID).Contains(GetEichelHighestPlayableCard(Wnd.TrickHistory)) Then
If .Item(n).ToString = GetEichelHighestPlayableCard(Wnd.TrickHistory) Then FindCard = .Item(n)
End If
If NonTrumpCards(hc, TrumpID).Contains(GetLaubHighestPlayableCard(Wnd.TrickHistory)) Then
If .Item(n).ToString = GetLaubHighestPlayableCard(Wnd.TrickHistory) Then FindCard = .Item(n)
End If
If NonTrumpCards(hc, TrumpID).Contains(GetSchellHighestPlayableCard(Wnd.TrickHistory)) Then
If .Item(n).ToString = GetSchellHighestPlayableCard(Wnd.TrickHistory) Then FindCard = .Item(n)
End If
Else
If hc.GetHighestCard(LeadSuitID, TrumpID) IsNot Nothing Then
If .Item(n).ToString = hc.GetHighestCard(LeadSuitID, TrumpID).ToString Then
FindCard = CardsPanel.Items.Item(n)
End If
End If
End If
If FindCard Is Nothing Then
Dim curCard As PlayingCard =
ACP.SelectBestFirstCard(CardsPanel, hc.PlayerID, Wnd.sk.declarer, Wnd.GameStatus,
sHand, TrumpID, hc, Wnd, LeadSuitID)
If curCard IsNot Nothing AndAlso curCard.CardType <> TrumpID Then
FindCard = curCard
If FindCard.CardValue = 2 Or FindCard.CardValue = 3 Then Wnd.sk.leadSuit = TrumpID
If FindCard.CardValue = 2 Or FindCard.CardValue = 3 Then LeadSuitID = TrumpID
End If
End If
Else
If FindCard Is Nothing Then
Dim curCard As PlayingCard =
ACP.SelectBestFirstCard(CardsPanel, hc.PlayerID, Wnd.sk.declarer, Wnd.GameStatus,
sHand, TrumpID, hc, Wnd, LeadSuitID)
If curCard IsNot Nothing AndAlso curCard.CardType <> TrumpID Then
FindCard = curCard
'If FindCard IsNot Nothing Then Debug.Print("ALL 77 FindCard: " & FindCard.ToString)
If FindCard.CardValue = 2 Or FindCard.CardValue = 3 Then Wnd.sk.leadSuit = TrumpID
If FindCard.CardValue = 2 Or FindCard.CardValue = 3 Then LeadSuitID = TrumpID
End If
End If
End If
Next
End If
End With
If FindCard IsNot Nothing Then Return FindCard
End Function
What I have tried:
public static PlayingCard SelectFirstCardCommonCheck_ALL(this HandCards hc, MainWindow Wnd, ListBox CardsPanel, int TrumpID, int LeadSuitID)
{
string sHand;
var FindCard = default(PlayingCard);
var ACP = new AutoCardPlay(Wnd.sk.trumpCard, Wnd);
sHand = hc.GetHandString();
{
var withBlock = CardsPanel.Items;
sHand = string.Empty;
if (Conversions.ToBoolean(Operators.ConditionalCompareObjectGreater(withBlock.Count, 0, false)))
{
for (int n = 0, loopTo = Conversions.ToInteger(Operators.SubtractObject(withBlock.Count, 1)); n <= loopTo; n++)
{
if (Wnd.iTricks > 5)
{
if (NonTrumpCards(hc, TrumpID) is not null)
{
if (NonTrumpCards(hc, TrumpID).Contains(Extensions_TrickMonitoring.GetEichelHighestPlayableCard(Wnd.TrickHistory)))
{
if ((withBlock.Item(n).ToString() ?? "") == (Extensions_TrickMonitoring.GetEichelHighestPlayableCard(Wnd.TrickHistory) ?? ""))
FindCard = (PlayingCard)withBlock.Item(n);
}
if (NonTrumpCards(hc, TrumpID).Contains(Extensions_TrickMonitoring.GetLaubHighestPlayableCard(Wnd.TrickHistory)))
{
if ((withBlock.Item(n).ToString() ?? "") == (Extensions_TrickMonitoring.GetLaubHighestPlayableCard(Wnd.TrickHistory) ?? ""))
FindCard = (PlayingCard)withBlock.Item(n);
}
if (NonTrumpCards(hc, TrumpID).Contains(Extensions_TrickMonitoring.GetSchellHighestPlayableCard(Wnd.TrickHistory)))
{
if ((withBlock.Item(n).ToString() ?? "") == (Extensions_TrickMonitoring.GetSchellHighestPlayableCard(Wnd.TrickHistory) ?? ""))
FindCard = (PlayingCard)withBlock.Item(n);
}
}
else if (hc.GetHighestCard(LeadSuitID, TrumpID) is not null)
{
if ((withBlock.Item(n).ToString() ?? "") == (hc.GetHighestCard(LeadSuitID, TrumpID).ToString() ?? ""))
{
FindCard = (PlayingCard)CardsPanel.Items.Item(n);
}
}
if (FindCard is null)
{
var curCard = ACP.SelectBestFirstCard(CardsPanel, hc.PlayerID, Wnd.sk.declarer, Wnd.GameStatus, sHand, TrumpID, hc, Wnd, LeadSuitID);
if (curCard is not null && (int)curCard.CardType != TrumpID)
{
FindCard = curCard;
if ((int)FindCard.CardValue == 2 | (int)FindCard.CardValue == 3)
Wnd.sk.leadSuit = TrumpID;
if ((int)FindCard.CardValue == 2 | (int)FindCard.CardValue == 3)
LeadSuitID = TrumpID;
}
}
}
else if (FindCard is null)
{
var curCard = ACP.SelectBestFirstCard(CardsPanel, hc.PlayerID, Wnd.sk.declarer, Wnd.GameStatus, sHand, TrumpID, hc, Wnd, LeadSuitID);
if (curCard is not null && (int)curCard.CardType != TrumpID)
{
FindCard = curCard;
if ((int)FindCard.CardValue == 2 | (int)FindCard.CardValue == 3)
Wnd.sk.leadSuit = TrumpID;
if ((int)FindCard.CardValue == 2 | (int)FindCard.CardValue == 3)
LeadSuitID = TrumpID;
}
}
}
}
}
if (FindCard is not null)
return FindCard;
return default;
}