| | |
pass in numbers?
![]() |
•
•
Join Date: Feb 2009
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Nov 2006
Posts: 442
Reputation:
Solved Threads: 73
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:
If you do not know how many parameters you are going to send, or the order then you can use a different approach:
To Call either of these methods you can format the call as such:
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:
Happy Coding // Jerry
If you plan on passing a strictly typed list then for your example:
C# Syntax (Toggle Plain Text)
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)
private void something(params object[] data )
To Call either of these methods you can format the call as such:
C# Syntax (Toggle Plain Text)
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)
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
![]() |
Similar Threads
- c language problm, how to pass pointer to a function (C)
- Selection Sort in java (Java)
- C++ Random Numbers (C++)
- need to pass and return arrays, how? (C++)
- Urgent! Help Me Pls (Assembly)
- Random numbers (ASP.NET)
- How do you pass objects as arguements? (Java)
Other Threads in the C# Forum
- Previous Thread: How to Count number of liens and Characters in a Tiff image ....
- Next Thread: DataGridView Control - Retrieving Information
Views: 413 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C#
.net 2d access algorithm application array asp.net bitmap box button c# check checkbox class code color combo combobox connectionproblem control conversion csharp custom data database datagrid datagridview dataset degrees directshow display dll drawing event excel expression file form format forms ftp function game gcd gdi+ graphics image index input install internet label list listbox listener login math mysql object operator photoshop picturebox print programming recursion remote remoting resource resourcefile round saving search server socket sql sql-server start statistics stream string text textbox thread threading time timer treeview tutorial update validation vc++ video view visual webbrowser webcam windows winforms wpf xml






