-6

Is there anyway to find out if my selected int number matches with one of my numbers in my number range int[] in this code?

Skaičiuoti means Count

    ButųKonteineris ArTenkinaKainą(ButųKonteineris butai, int[] kainųIntervalas)
    {
        ButųKonteineris artenkinakainąbutai = new ButųKonteineris(butai.Skaičiuoti);
        for (int i = 0; i < butai.Skaičiuoti; i++)
        {
            if (butai.PaimtiButą(i).Kaina == kainųIntervalas)
            {
                butai.PridetiButą(butai.PaimtiButą(i));
            }
        }
        return artenkinakainąbutai;
    }
Dom As
  • 3
  • 2

1 Answers1

0

You need to use the LINQ extension method .Contains(). So if your array of integers is called kainųIntervalas, and you want to check if it contains the integer 42, it would be

if (kainųIntervalas.Contains(42))
{
    // success!
}

Or to verify your butai.PaimtiButą(i).Kaina

if (kainųIntervalas.Contains(butai.PaimtiButą(i).Kaina))
{
    butai.PridetiButą(butai.PaimtiButą(i));
}

note that you need the System.Linq namespace for this:

using System.Linq;
Rand Random
  • 7,300
  • 10
  • 40
  • 88
Bas
  • 1,946
  • 21
  • 38