Link to home
Start Free TrialLog in
Avatar of lancerxe
lancerxe

asked on

Not getting a value from a 1 dimentional array

Hello experts:

Can someone please tell me why the code snippet below does not work.
The loop works and it populates RecContent just fine
but LDAcctNo is not populated

for (intCounter = 0; intCounter <= intLastElement; intCounter++)
{
RecContent = LoanDetArray.GetValue (intCounter).ToString();
LDAcctNo = RecContent.ToCharArray(0,20).ToString();
}
                                          
Thanks
Avatar of AdGroot
AdGroot


If I look at your code you are filling RecContent in a loop
you must assign LDAcctNo after you have finished de loop

for (intCounter = 0; intCounter <= intLastElement; intCounter++)
{
RecContent = LoanDetArray.GetValue (intCounter).ToString();
}

LDAcctNo = RecContent.ToCharArray(0,20).ToString();

Ad
Avatar of lancerxe

ASKER

Everytime the RecContent is populated I need to
get the LDAcctNo also
 
How can I make the LDAcctNo = RecContent.ToCharArray(0,20).ToString();
part of the loop?
I think i mist the point,
I just tried your code,

do you get a exception ???

you do not check the length of RecCont.

change the code to

                LDAcctNo = RecContent.ToCharArray(0, Math.Min(20,RecContent.Length)).ToString();

I hope that this is your problem

what are the types of LDAcctNo and RecContent ??

Ad

I don't get an exception
but when I step thru the code
RecContent gets populated and the 1st record has accountnumber 00000000000000000001
but LDAcctNo does not.
When I put the cursor on top of it , it says "System.Char[]". I was expecting to see 00000000000000000001

I get this error with my original code or your code.  

Both are strings
 
ASKER CERTIFIED SOLUTION
Avatar of AdGroot
AdGroot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That was it
Thanks