String length

M

mohammad asseedeh

now my question is to find the length of any String manualy we will
use
a loop and this with order O(n) where n is the number of chars in the
String, now is theres a way to find the length of any String with
order one that means O(1) in one hit???!!! this is my question
 
N

Nicholas Paldino [.NET/C# MVP]

What is wrong with the Length property on the string? It should be
pretty quick for your needs.
 
A

Andrew Faust

Indeed, it does exactly what he's asking for O(1). I merely reads and
actual field where the current length is always stored.

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com


Nicholas Paldino said:
What is wrong with the Length property on the string? It should be
pretty quick for your needs.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mohammad asseedeh said:
now my question is to find the length of any String manualy we will
use
a loop and this with order O(n) where n is the number of chars in the
String, now is theres a way to find the length of any String with
order one that means O(1) in one hit???!!! this is my question
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top