Length of string in array

M

Michael C

I have an array of strings

string[] strArray = new string[10];

strArray[5] = "ABC";

How can I determine the number of characters in the array item?

if (strArray[5].length = = 3)
{
}

This is acually returning 10 which is the array length

I want the array item string.length

Thanks

Michael
 
K

Kyril Magnos

That is correct though...

Console.WriteLine(strArray[5].Length);

That should return 3.

Maybe you called strArray.Length without an indexer?

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :)

|I have an array of strings
|
| string[] strArray = new string[10];
|
| strArray[5] = "ABC";
|
| How can I determine the number of characters in the array item?
|
| if (strArray[5].length = = 3)
| {
| }
|
| This is acually returning 10 which is the array length
|
| I want the array item string.length
|
| Thanks
|
| Michael
|
|
 
C

cody

Maybe try something like (strArray[5]).Length.

This should make no difference, does it :)

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Peter Rilling said:
Maybe try something like (strArray[5]).Length.


Michael C said:
I have an array of strings

string[] strArray = new string[10];

strArray[5] = "ABC";

How can I determine the number of characters in the array item?

if (strArray[5].length = = 3)
{
}

This is acually returning 10 which is the array length

I want the array item string.length

Thanks

Michael
 
P

Peter Rilling

You are right that it should not, but since the problem was that Length was
being applied to the array rather then the array element, this was all that
I could think of. There is nothing like being explicit when troubleshooting
code.


cody said:
Maybe try something like (strArray[5]).Length.

This should make no difference, does it :)

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Peter Rilling said:
Maybe try something like (strArray[5]).Length.


Michael C said:
I have an array of strings

string[] strArray = new string[10];

strArray[5] = "ABC";

How can I determine the number of characters in the array item?

if (strArray[5].length = = 3)
{
}

This is acually returning 10 which is the array length

I want the array item string.length

Thanks

Michael
 
J

Jon Skeet [C# MVP]

Peter Rilling said:
You are right that it should not, but since the problem was that
Length was being applied to the array rather then the array element,
this was all that I could think of. There is nothing like being
explicit when troubleshooting code.

I think the problem is that we weren't seeing the actual code. The code
posted certainly wouldn't compile (due to the space in the comparison)
so I suspect it wasn't the real code.
 

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