In this example, i’ll show you How to return an array from method in C#.
Example 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | internal class Program { static string[] GetNames() { string[] lang = { "C#", "C++", "Java", "Python" }; return lang; } static void Main(string[] args) { string[] strArr = GetNames(); foreach(string str in strArr) { Console.WriteLine(str); } Console.ReadKey(); } } |
Output:
