

- 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
Passing arrays to methods in C#?
To pass arrays to methods, you need to pass an array as a method argument.
int displaySum(int[] arr, int size) { }
Now call it −
sum = d.displaySum(myArr, 5 ) ;
Example
using System; namespace Test { class Demo { int displaySum(int[] arr, int size) { int i; int sum = 0; for (i = 0; i < size; ++i) { sum += arr[i]; } return sum; } static void Main(string[] args) { Demo d = new Demo(); int [] myArr = new int[] {59, 34, 76, 65, 12, 99}; int sum; sum = d.displaySum(myArr, 5 ) ; /* output the returned value */ Console.WriteLine( "Sum: {0} ", sum ); Console.ReadKey(); } } }
Output
Sum: 246
- Related Questions & Answers
- Passing Arrays to Function in C++
- Passing static methods as arguments in PHP
- What are different methods of passing parameters in C#?
- How to pass Arrays to Methods in Java?
- Passing by pointer Vs Passing by Reference in C++
- What are new methods have added to the Arrays class in Java 9?
- Passing to method geticon in SAPUI5
- Passing array to method in Java
- Passing Lists to Subroutines in Perl
- Passing Hashes to Subroutines in Perl
- Passing a vector to constructor in C++
- Passing Arguments to a Subroutine in Perl
- Passing parameters to callback functions JavaScript
- Passing the Assignment in C++
- Sorting an integer without using string methods and without using arrays in JavaScript
Advertisements