Array as Argument

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2005
Posts: 109
Reputation: complete is an unknown quantity at this point 
Solved Threads: 0
complete's Avatar
complete complete is offline Offline
Junior Poster

Array as Argument

 
0
  #1
Feb 7th, 2008
How do you pass an array of integers as an argument to a method in C#?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Array as Argument

 
0
  #2
Feb 7th, 2008
public void YourMethod(int[] arrOfInts)
{
//your code goes here..
}
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2009
Posts: 1
Reputation: aravindsp is an unknown quantity at this point 
Solved Threads: 0
aravindsp aravindsp is offline Offline
Newbie Poster
 
-1
  #3
8 Days Ago
Originally Posted by complete View Post
How do you pass an array of integers as an argument to a method in C#?
  1. void ShowNumbers (params int[] numbers)
  2. {
  3. foreach (int x in numbers)
  4. {
  5. Console.Write (x+" ");
  6. }
  7. Console.WriteLine();
  8. }
  9.  
  10. ...
  11.  
  12. int[] x = {1, 2, 3};
  13. ShowNumbers (x);
  14. ShowNumbers (4, 5);
Last edited by niek_e; 7 Days Ago at 3:45 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 48
Reputation: privatevoid is an unknown quantity at this point 
Solved Threads: 6
privatevoid's Avatar
privatevoid privatevoid is offline Offline
Light Poster
 
0
  #4
7 Days Ago
Note that the params keyword is not required unless you are going to add individual ints as multiple parameters to the method.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 2368 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC