Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:24:55+00:00 2026-06-18T16:24:55+00:00

Hi I was trying to find the number of elements in an array byte[]

  • 0

Hi I was trying to find the number of elements in an array

byte[] salt = new byte[32];

now I only have mentioned size 32 so the Length Property of Array and Enumerable’s Count Method will give me 32.

Even if I will iterate on this Array salt using for or foreach or any other looping construct it will iterate 32 times and on each index the value is 0 (i.e default value of byte)

Now suppose I do:

for (int i = 0; i < 5 ; i++)
        {
            salt[i] = 4-i;
        }

And I want to know how many elements are inserted sequentially in Array starting from index 0, Here you may say are you fool you iterating it 5 times and you know the number is 5 , but I am having heavy looping and other logic (appending prepending to another arrays of byte) in it. *My question Is there any other inbuilt function that could give me this number 5 ? * Even if I iterate and check for first default value and break the loop there and get the count but there might be the chance last value inserted is 0 like above salt[4] is 0 so that iterating will give me the count 4 which is incorrect . If I am not wrong I think when we declare Array with size like 32 above 32 consecutive memory bytes are reserved and you are free to insert at any index from 0-31 and its your responsibility to keep the track where and how and how many elements are assigned to Array .I hope you got my point And thanks in advance for help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:24:56+00:00Added an answer on June 18, 2026 at 4:24 pm

    An array is an array, and in .NET is initialized when it is allocated. Once it’s initialized, the question of whether a given value is uninitialized or simply 0 isn’t something that’s possible to check. A 0 is a 0.

    However, you can bypass that in several ways. You can use a List<int>, like @SLaks suggested, to have a dynamically allocated list that’s only initialized with the elements you want.

    You can also use, instead of an array of int, and array of int?, so a null value isn’t the same as a 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find number of unique characters in a String. Solution have
I have an Array {-1,0,1,2,3,4...} I am trying to find whether an element exist
There is an array of integers ,I have to find the number of sequences
** Update - trying to find the number of elements with an empty src
I'm trying to find the minimum number in a array using Thrust and CUDA.
I'm trying to find the number of employees joined over a calender year, broken
I'm trying to find an integer number of days between two dates in Oracle
I am trying to find some float number (like -1234.5678) in a huge text
I am trying to find all floating number (could be in exponential forms with
I am writing a simple program, which is trying to find next palindrome number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.