Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return a variable length string array

Tags:

c#

.net

what's the best method to return a variable length string array

like image 863
user496949 Avatar asked May 19 '26 23:05

user496949


2 Answers

I'd prefer to use a generic collection such as: List<string> (or IList<string>), or IEnumerable<string> depending on how you plan to use it. Generic collections are typically easier to work with than arrays, having a much more robust interface.

like image 66
tvanfosson Avatar answered May 21 '26 14:05

tvanfosson


There is nowhere near enough detail in your question to understand exactly what you are after.

This works though:

string[] GetStringArray(int length) {
    return new string[length];
}

(C# isn't like C, if that is your concern.)

like image 31
jason Avatar answered May 21 '26 13:05

jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!