checking sequence of numbers through byte array in c#

Actually i need to check the sequence of elements in an byte array in c#
where here "d" and "q" are character arrays.

here the below 2 lines are converting it into byte[]
iam getting error at    "if((item)==p.Contains(Convert.ToInt32(item)+1))"
byte[] p = Encoding.UTF8.GetBytes(d);
            byte[] r = Encoding.UTF8.GetBytes(q);
         
            foreach (var item in p)
            {
                if((item)==p.Contains(Convert.ToInt32(item)+1))
                {
                    count1 += 1;
                }

could you please help the error is byte[] doesnot contain 'contains' .
Gayathri GrandheAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MishaProgrammerCommented:
I see two methods:
1) Use List<byte>  instead of array.
2) Use IndexOf
int pos = p.IndexOf("yourValue");
if (pos > -1)
{
  //do something
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gayathri GrandheAuthor Commented:
i converted it into list and i can able to get some clues

  List<byte> p = Encoding.UTF8.GetBytes(d).ToList();
            List<byte> r = Encoding.UTF8.GetBytes(q).ToList();
         
            foreach (var item in p)
            {
                if(Convert.ToBoolean(item)==p.Contains(Convert.ToByte((item)+1)))
                {
//operation
}
}
0
Chris StanyonWebDevCommented:
You can do this very simply with LINQ.

If you just want to increase the count based on the number of matches:

var p = Encoding.UTF8.GetBytes(d).ToList();
count += p.Count(item => p.Contains(++item));

Open in new window

If you want to loop over just the matches:

var p = Encoding.UTF8.GetBytes(d).ToList();
foreach (var item in p.Where(item => p.Contains(++item)))
{
    Console.WriteLine($"Match: {item}");
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.