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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an array from a method

Status
Not open for further replies.

pmcmicha

Technical User
May 25, 2000
353
I am attempting to construct an array from a method, but I am receiving an error that the array must have an array size or array initializer. I thought the code below would do this, but it seems that C# is wanting more information up front, and I am not entirely sure what to give it. If I try to add "new string[] method", that does not work either.

Code:
string[] testArray = testFunction(Directory);

public string[] BuildDirArr(string dirtoproc) {
[indent]string[] getAllDirs = Directory.GetDirectories(dirtoproc);[/indent]

[indent]// Do pattern matching on the directories here in a for loop, discarding those that do not match.[/indent]
[indent]//+ The for loop adds good directories to a list, then I do a list to array conversion before doing return.[/indent]

[indent]return(MatchingDirs);[/indent]
}

Thanks in advance.
 
Seems the answer was to add static to the method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top