我有兩個列表,我需要比較正確的位置:比較列表來確定範圍內的List <>
var list = new Guess(guesses, 0 , 0);// see class for constructor
和
theGame.Target = guesses;
var list2 = theGame.Target;
我需要做到以下幾點:
GuessTheDigits
套數RightDigitsInTheRightPosition
正確
個GuessTheDigits:
public ActionResult GuessTheDigits(List<int> guesses)
{
GuessingGame theGame = this.Session["GameState"] as GuessingGame;
// pass to the method
theGame.GuessTheHiddenDigits(guesses);
//set the lists
var list = new Guess();
theGame.Target = guesses;
var list2 = theGame.Target;
//need to compare lists here
// Redirect to action
return RedirectToAction("Index", theGame.Guesses);
}
類如下:
猜測類
public class Guess
{
public Guess()
: this(new List<int>() { 1, 2, 3 }, 0, 0)
{
}
public Guess(List<int> guesses, int rdrp, int rdwp)
{
this.Digits = guesses;
this.RightDigitRightPosition = rdrp;
this.RightDigitWrongPosition = rdwp;
}
public Guess(List<int> guesses, int rdrp)
: this(guesses, rdrp, 0)
{
}
public Guess(List<int> guesses)
: this(guesses, 0, 0)
{
}
public List<int> Digits { get; set; }
public int RightDigitRightPosition { get; set; }
public int RightDigitWrongPosition { get; set; }
}
以前嘗試代碼:
var check = list2.Where(s => !theGame.Guesses.Contains(list));
foreach (var i in check)
{
list.RightDigitRightPosition = i;
}
_「以前試過的代碼」_是否有效?如果不是,發生了什麼問題? –
我會誠實的說,你仍然不清楚你想要做什麼。請嘗試以非常簡潔的方式解釋目標。 –
@TimSchmelter - 它不是比較列表,而是將list.RightDigitRightPosition分配給列表中每個項目的值。 –