

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Questions & Answers
- MongoDB query to return specific fields from an array?
- C# Program to return specified number of elements from the end of an array
- How to return an array from a method in Java?
- How to return an array from a function in C++?
- Return the first duplicate number from an array in JavaScript
- Java Program to copy an array from the specified source array
- PHP program to find missing elements from an array
- Java Program to Remove Duplicates from an Array List
- C# Program to display the first element from an array
- C# program to get the last element from an array
- C# Program to find the largest element from an array
- C# Program to find the smallest element from an array
- Java Program to generate a random number from an array
- Specify return format in MongoDB to return the values as an array?
- Return Top two elements from array JavaScript
Advertisements