Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning arraylist.toArray() in function

Status
Not open for further replies.

DarwinIT

Programmer
Apr 25, 2008
142
US
I need to use an arraylist because I don't know how many entries will be going into my array. In my calling routine I have

string[] myStringArray = functionName(arg1,arg2)


in the function I build the arraylist and then have

} return myArraylist.ToArray();

I have a type mismatch between object and string. I'm guessing I need to cast somewhere but I can't figure out where or how. I could simply create a string[] and populate it and return it - but I'm trying to learn C# here. That will never happen if I choose to do inefficient hacks that work but don't allow me to discover how things should be done.

Thanks!
 
what is myArraylist defined as? if you need to return strings. then define a List<string>, populate and call ToArray();

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
It was defined as an arrayList. I defined it as a List<string> and it worked like a champ. Thanks a bunch!!!
Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top