943,901 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 505
  • C# RSS
Feb 20th, 2009
0

pass in numbers?

Expand Post »
is there a way to pass in numbers(int) like this?

somename([0,0],[2,4],3);

thanks for any help
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
JackDurden is offline Offline
92 posts
since Jun 2008
Feb 20th, 2009
2

Re: pass in numbers?

You mean pass in arrays of numbers? Yes, use arrays.
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Feb 21st, 2009
0

Re: pass in numbers?

Click to Expand / Collapse  Quote originally posted by JackDurden ...
is there a way to pass in numbers(int) like this?

somename([0,0],[2,4],3);

thanks for any help

solution-yes we can pass it like this:
int a[0,0],b[2,4];
int c=3;
we can declare these variables seperately like this ...but collectively we can't do this as u asked...
i think the method i told u ..it will definitely help u....try it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
poorvi_tiwari is offline Offline
2 posts
since Feb 2009
Feb 21st, 2009
0

Re: pass in numbers?

Passing parameters to a method requires the correct parameter list declaration in the Method construct.

If you plan on passing a strictly typed list then for your example:
C# Syntax (Toggle Plain Text)
  1. private void something(int[] a, int[] b, int c)

If you do not know how many parameters you are going to send, or the order then you can use a different approach:
C# Syntax (Toggle Plain Text)
  1. private void something(params object[] data )

To Call either of these methods you can format the call as such:
C# Syntax (Toggle Plain Text)
  1. something(new int[] { 0, 1 }, new int[] { 2, 3 }, 3);

Note that if you have both of these method constructs, the more exact version is what will be used:
IOW the one with the something(int[] a, int[] b, c) is prime because it exactly meets the parameters being called.
If you rearrange the parameters so that the int is in position 0 or one, then it uses the something( params object[] data) version.

To use the "params" version you could do something like this:
C# Syntax (Toggle Plain Text)
  1. private void something(params object[] data )
  2. {
  3. int sum = 0;
  4. int[] somearray;
  5. foreach (object obj in data)
  6. {
  7. if(obj.GetType() == typeof(int[]))
  8. {
  9. somearray = (int[])obj;
  10. foreach (int n in somearray)
  11. sum += n;
  12. }
  13. else if (obj.GetType() == typeof(int))
  14. {
  15. sum += (int)obj;
  16. }
  17. }
  18. MessageBox.Show(sum.ToString());
  19. }

Happy Coding // Jerry
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How to Count number of liens and Characters in a Tiff image ....
Next Thread in C# Forum Timeline: DataGridView Control - Retrieving Information





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC