How to declare string array?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 1, 2013, 1:56 AM EDT
You can declare like this
Regards,
Iftikar
VulpesRank #55 · 29.2K reputationPosted Aug 1, 2013, 1:56 AM EDT
string[] numbers = new string[5]{"1", "2", "3", "4", "5"};
or:
string[] numbers = new string[]{"1", "2", "3", "4", "5"}; // compiler works out number of elements
or simply:
string[] numbers = {"1", "2", "3", "4", "5"}; // compiler deduces type and size