473,565 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to disable "params"

Is there any way to disable the "params" on a particular invocation so that
one can pass an array containing the arguments and not have receiver get an
array having you argument array stuffed into the first index?

I have worked around this by getting the MethodInfo via reflection and
invoking it there. Is there a simpler way?

Thanks,

Stan
Nov 17 '05 #1
3 1646
Stan,
| Is there any way to disable the "params" on a particular invocation so
that
| one can pass an array containing the arguments
This is the standard behavior for "params"!

| and not have receiver get an
| array having you argument array stuffed into the first index?

Consider the following function:

static int Sum(params int[] values)
{
int total = 0;
foreach(int value in values)
{
total += value;
}
return total;
}

Given:
int[] values = {1,2,3,4,5};
int total;

You can call it with either of:

total = Sum(1,2,3,4,5);
total = Sum(values);

NOTE: That the type of the array (int[] values) matches the type of the
params parameter (int[]). It will not work if you attempt to pass a int[]
variable to a object[] parameter, as the "shape" of the parameters don't
match.

Hope this helps
Jay

"Stan Huff" <no*****@nowher e.com> wrote in message
news:Op******** ******@TK2MSFTN GP14.phx.gbl...
| Is there any way to disable the "params" on a particular invocation so
that
| one can pass an array containing the arguments and not have receiver get
an
| array having you argument array stuffed into the first index?
|
| I have worked around this by getting the MethodInfo via reflection and
| invoking it there. Is there a simpler way?
|
| Thanks,
|
| Stan
|
|
Nov 17 '05 #2
Thanks Jay. I went back tried the obvious method and it worked. At some
point in the past I recalled having some issue here, but apparently I was
mistaken. Good thing to know...

Stan

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OR******** ********@TK2MSF TNGP10.phx.gbl. ..
Stan,
| Is there any way to disable the "params" on a particular invocation so
that
| one can pass an array containing the arguments
This is the standard behavior for "params"!

| and not have receiver get an
| array having you argument array stuffed into the first index?

Consider the following function:

static int Sum(params int[] values)
{
int total = 0;
foreach(int value in values)
{
total += value;
}
return total;
}

Given:
int[] values = {1,2,3,4,5};
int total;

You can call it with either of:

total = Sum(1,2,3,4,5);
total = Sum(values);

NOTE: That the type of the array (int[] values) matches the type of the
params parameter (int[]). It will not work if you attempt to pass a int[]
variable to a object[] parameter, as the "shape" of the parameters don't
match.

Hope this helps
Jay

"Stan Huff" <no*****@nowher e.com> wrote in message
news:Op******** ******@TK2MSFTN GP14.phx.gbl...
| Is there any way to disable the "params" on a particular invocation so
that
| one can pass an array containing the arguments and not have receiver get
an
| array having you argument array stuffed into the first index?
|
| I have worked around this by getting the MethodInfo via reflection and
| invoking it there. Is there a simpler way?
|
| Thanks,
|
| Stan
|
|

Nov 17 '05 #3
Stan,
| point in the past I recalled having some issue here,
Its easy to have an "issue" with it. Consider:

void Write(string format, params object[] values) { ... }

int[] values = {1, 2, 3, 4, 5};

Write(theFormat , values);

Because Write expects object params & I am attempting to send it an int
array, the int array will be put into an object array...

Hope this helps
Jay

"Stan Huff" <no*****@nowher e.com> wrote in message
news:ul******** ******@TK2MSFTN GP14.phx.gbl...
| Thanks Jay. I went back tried the obvious method and it worked. At some
| point in the past I recalled having some issue here, but apparently I was
| mistaken. Good thing to know...
|
| Stan
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
| news:OR******** ********@TK2MSF TNGP10.phx.gbl. ..
| > Stan,
| > | Is there any way to disable the "params" on a particular invocation so
| > that
| > | one can pass an array containing the arguments
| > This is the standard behavior for "params"!
| >
| > | and not have receiver get an
| > | array having you argument array stuffed into the first index?
| >
| > Consider the following function:
| >
| > static int Sum(params int[] values)
| > {
| > int total = 0;
| > foreach(int value in values)
| > {
| > total += value;
| > }
| > return total;
| > }
| >
| > Given:
| > int[] values = {1,2,3,4,5};
| > int total;
| >
| > You can call it with either of:
| >
| > total = Sum(1,2,3,4,5);
| > total = Sum(values);
| >
| > NOTE: That the type of the array (int[] values) matches the type of the
| > params parameter (int[]). It will not work if you attempt to pass a
int[]
| > variable to a object[] parameter, as the "shape" of the parameters don't
| > match.
| >
| > Hope this helps
| > Jay
| >
| >
| >
| > "Stan Huff" <no*****@nowher e.com> wrote in message
| > news:Op******** ******@TK2MSFTN GP14.phx.gbl...
| > | Is there any way to disable the "params" on a particular invocation so
| > that
| > | one can pass an array containing the arguments and not have receiver
get
| > an
| > | array having you argument array stuffed into the first index?
| > |
| > | I have worked around this by getting the MethodInfo via reflection and
| > | invoking it there. Is there a simpler way?
| > |
| > | Thanks,
| > |
| > | Stan
| > |
| > |
| >
| >
|
|
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
3627
by: Oliver Fromme | last post by:
Hi, I'm trying to write a Python function that parses an expression and builds a function tree from it (recursively). During parsing, lambda functions for the the terms and sub-expressions are constructed on the fly. Now my problem is lazy evaluation. Or at least I think it is. :-)
5
8735
by: charliewest | last post by:
I've implemented the USING statement to ensure that my newly created sql connection closes when my method is finished using it. The USING statement is wrapped in try/catch error handling statement. This works fine. When i try to implement the "SqlTransation" class, the code does not work as the SqlTransation object is out-of-scope in the...
9
6248
by: Hasan O. Zavalsiz | last post by:
Hi , i am trying to figure out which approach is better to use . let me explain the scenario. i am using the "Nortwind" database . in this database i have "Customers " table .The following is the two different ways to handle this table. CASE 1 : create a struct that encaplusates table "Customers" columns public struct structCustomers {...
28
2920
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions! PEP: 359 Title: The "make" Statement Version: $Revision: 45366 $ Last-Modified: $Date: 2006-04-13 07:36:24 -0600 (Thu, 13 Apr 2006) $
16
5130
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString Page.FindControl("tdInput").Controls.Add(txtTest) This successfully creates a textbox called "txtLeft1" in the table
1
2343
by: patelxxx | last post by:
Hi Guy's, I'm getting the error: "Username or password did not match" BEFORE I even enter a username and password, can someone help? 1) The site I'm accessing is: http://www.valuemapping.co.uk/VMSE/ 2) Then I click/select the following application: "VMSE Reporting" and get the above error. The CGI script for this is:
1
1285
by: Claire | last post by:
Hi, either I'm going mad or is params not working anymore in VS 2005? I have function as follows public tableEquipment ReadEquipment(bool ReadImages, params Int64 RecIDs) { } if I call "tableEquipment equipment = myDatabase.ReadEquipment(false, RecID);"
2
2095
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
6
1599
by: Luigi | last post by:
Dear all, I'm writing an XML-RPC server which should be able to modify the incoming request before dispatching it. In particular I wand to added two fixed parameters to the method called: one is the client host address, and the other is the user name provided as for Basic Authentication (http://user@www.bla-bla.com). To do this, at the...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.