954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pass in numbers?

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

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

thanks for any help

JackDurden
Junior Poster in Training
92 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

You mean pass in arrays of numbers? Yes, use arrays.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

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

poorvi_tiwari
Newbie Poster
2 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

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:

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:

private void something(params object[] data )


To Call either of these methods you can format the call as such:

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:

private void something(params object[] data )
        {
            int sum = 0;
            int[] somearray;
            foreach (object obj in data)
            {
                if(obj.GetType() == typeof(int[]))
                {
                    somearray = (int[])obj;
                    foreach (int n in somearray)
                        sum += n;
                }
                else if (obj.GetType() == typeof(int))
                {
                    sum += (int)obj;
                }
            }
            MessageBox.Show(sum.ToString());
        }


Happy Coding // Jerry

JerryShaw
Posting Pro in Training
465 posts since Nov 2006
Reputation Points: 69
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You