4

C# array byte[].Length property.

byte[] buffer = new ...

When call int i = buffer.Length; I can see get_Length() in reflector,

What happens? Does it calculate actual length or just takes value (like property) ???

5
  • codeproject.com/KB/dotnet/arrays.aspx Commented Jul 12, 2011 at 19:24
  • 2
    get_Length() is just part of how .NET implements the getter on the Length property. Commented Jul 12, 2011 at 19:48
  • 2
    Why did you edit your question to delete most of it? It's now impossible to understand what the question is. Commented Mar 28, 2016 at 13:58
  • it's not me. my account was hacked Commented Mar 28, 2016 at 18:02
  • Question restored Commented May 24, 2017 at 6:26

2 Answers 2

10

byte[].Length will tell you the total number of elements in the array, so retrieving this property has a complexity of O(1).

Sign up to request clarification or add additional context in comments.

Comments

7

Arrays are fixed-length; the Length property returns an internal field in the array.
(It's O(1), not O(n))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.