© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
Matt

❔ Array.IndexOf being weird

I'm very confused. Been trying to use Array.IndexOf to find a null terminator in a byte array
int endOfString = Array.IndexOf(Data, 0x0, EntryNameTableOffset + entry.NameTableOffset);
int endOfString = Array.IndexOf(Data, 0x0, EntryNameTableOffset + entry.NameTableOffset);

But it fails to find the byte and returns -1

Doing this however, it finds the byte... O_O
Why does Array.IndexOf not work in this situation?
for (int x = EntryNameTableOffset + entry.NameTableOffset; x < Data.Length; x++)
{
    if (Data[x] == 0x0)
    {
        endOfString = x;
        break;
    }
}
for (int x = EntryNameTableOffset + entry.NameTableOffset; x < Data.Length; x++)
{
    if (Data[x] == 0x0)
    {
        endOfString = x;
        break;
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

IndexOf being weird? (Advent of Code day1 semi-spoiler?)
C#CC# / help
3y ago
if statement is being weird
C#CC# / help
2y ago
❔ Visual Studio Code being weird.
C#CC# / help
3y ago
I'm having trouble with an IndexOf returning the position in a array
C#CC# / help
3y ago