Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# program to return an array from methods
Call a method under Join method to join words −
string.Join(" ", display())
Now set a string array −
string[] str = new string[5];
Add individual elements −
str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt";
And return the same string array from method −
return str;
The following is the complete code −
Example
using System;
public class Demo {
public static void Main() {
Console.WriteLine(string.Join(" ", display()));
}
static string[] display() {
string[] str = new string[5];
// string array elements
str[0] = "My";
str[1] = "name";
str[2] = "is";
str[3] = "Brad";
str[4] = "Pitt";
return str;
}
}
Output
My name is Brad Pitt
Advertisements
