473,848 Members | 1,829 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 1657
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
3716
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
8775
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 catch statement, and/or, after the USING statement ends, the sql connection object is automatically...
9
6265
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 { public string CustomerID;
28
2964
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
5194
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
2361
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
1299
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
2113
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
1612
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 present I've overwritten the do_POST method of SimpleXMLRPCRequestHandler, including at a certain...
0
9893
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9738
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10664
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10348
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7069
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4544
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
3
3175
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.