473,657 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing params object[] args signatured method's parameters to another -same signatured- method.

code snippet below briefly shows what i need to do :

public void Method1(params object[] args)
{
Method2(args);
}

public void Method2(params object[] args)
{
//Do something.
}
in Method1 i pass all coming parameters to Method2, but i thing it will call
Method2 such a Method2(object[] args)... to be more clear, i would access
parameters in Method2 like args[0][0], args[0][1] ..... how can i prevent
this?
Nov 17 '05 #1
7 8484
The Crow wrote:
code snippet below briefly shows what i need to do :

public void Method1(params object[] args)
{
Method2(args);
}

public void Method2(params object[] args)
{
//Do something.
}
in Method1 i pass all coming parameters to Method2, but i thing it will
call Method2 such a Method2(object[] args)... to be more clear, i would
access parameters in Method2 like args[0][0], args[0][1] ..... how can i
prevent this?


Where do you get this idea from? Why don't you just try it?
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
Nov 17 '05 #2
"The Crow" <q> schrieb im Newsbeitrag
news:uf******** ******@TK2MSFTN GP14.phx.gbl...
code snippet below briefly shows what i need to do :

public void Method1(params object[] args)
{
Method2(args);
}

public void Method2(params object[] args)
{
//Do something.
}
in Method1 i pass all coming parameters to Method2, but i thing it will
call Method2 such a Method2(object[] args)... to be more clear, i would
access parameters in Method2 like args[0][0], args[0][1] ..... how can i
prevent this?

Did you test it?
It should use the normal form of Method2 since it is applicable.

From the spec:
<quote>
The expanded form of a method is available only if the normal form of the
method
is not applicable and only if a method with the same signature as the
expanded form
is not already declared in the same type.
</quote>

To call the expanded form (i.e. to args of Method1 will be the one element
of args in Method2),
you'll have to call:
Method2((object )args);

Christof
Nov 17 '05 #3
ive got this idea from, thinking the type of args as a normal array. but
yes, you are right i should have tried it. it worked as expected to be.
now i wonder, what is the actual type of args? a special type?
i think c# compiler do some trick behind the scenes around there. what do
you think?
Nov 17 '05 #4
"The Crow" <q> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
ive got this idea from, thinking the type of args as a normal array. but
yes, you are right i should have tried it. it worked as expected to be.
now i wonder, what is the actual type of args? a special type?
i think c# compiler do some trick behind the scenes around there. what do
you think?

the type of args is object[] in both cases.
the paramarray keyword only changes the way it can be called.
If the expanded form is called c# creates an array of the given type and
put's the
parameters in it.
See my other post about when the expanded form is considered by the
compiler.
Nov 17 '05 #5
only public static int GetValue2(bool[] args) is called. then what is the
benefit of supplying params keyword before the paremter rather then using
bool[] args? (int this situation of course)

using System;

using System.IO;

using System.Windows. Forms;

using System.Net;

namespace ConsoleApplicat ion1

{

/// <summary>

/// Summary description for Class1.

/// </summary>

class Class1

{

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

try

{

GetValue(true, false);

}

catch(Exception ex)

{

Console.WriteLi ne(ex.Message);

}

Console.ReadLin e();

}

public static int GetValue(params bool[] args)

{

return GetValue2(args) ;

}

public static int GetValue2(bool param1, bool param2)

{

if(param1)

return 1;

else

return 0;

}

public static int GetValue2(bool[] args)

{

if(args[0])

return 1;

else

return 0;

}

}

}
Nov 17 '05 #6
ok. i was always late for my other 2 posts. now everything is clear.
Nov 17 '05 #7
should be params where i wrote paramarray ;-)
Nov 17 '05 #8

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

Similar topics

1
18277
by: Michael Hetrick | last post by:
How would I pass parameters to a console application? I would like to do something like this: consoleapp.exe /o \\fileshare\origindirectory /d \\fileshare\destinationdirectory I'm not sure how to start the console app to read from the command line. Any assistance would be appreciated! Michael Hetrick
3
8047
by: rollasoc | last post by:
Hi, Having a slight problem with how to pass parameters to functions between threads. I have a form with a progress bar and a description label on it. It has a public function IncrementProgressBar() that just calls performstep on the progress bar.
0
1407
by: Efkas | last post by:
I am trying some interresting features to load an assembly on the fly. I read some samples, but what I am trying to do is a little more complex. - First, I have a app.config file containing keys like "mydll_MyClass.dll" - Second, I tried to load the assembly with Assembly.LoadFrom(myDll), but since my constructor having some parameters this is not possible. - Third, I tried Activator.CreateInstance(...), but it becomes very
1
1275
by: craigkenisston | last post by:
Hi, I'm trying to create a generic function to call stored procedures in a SQL Server database. I'm passing the params, values and the direction of the params in arrays. The function is working, and I get the output parameters values back in my the array I sent, however, I'd like to have the values in my original variables, please see below :
1
2519
by: raf_z | last post by:
Hi, I'm running a website with Asp.NET, and on one of the pages i have a crystal report with 3 user-populated parameters. However, not all params might be selected. Example: Parameters: 1. EmployeeID 2. First Name 3. Last Name
0
1436
by: Mike | last post by:
Hi, I am trying to insert parameters into a stored procedure using DAAB (see code at the bottom of this post). I am getting the following error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:...
12
6892
by: Dennis D. | last post by:
Hello: I want a function to return three variables to the calling procedure: Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as Integer, ByVal iAddMins as Integer) As Array Variable values are calculated in the function. Calling procedure receives the values preferably into variables of the same
2
3342
by: Brett | last post by:
How do I receive command line parameters being passed into my application? Say I call the application from within MS Access and it passes me an ID. How do I receive the ID in the VB.NET app? Thanks, Brett
4
2375
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript. Because I want to use some ajax-requests and other javascript-functions on my xhtml, I need to dynamically add event handlers to any possible dom-elements. All solutions I found so fare are for specific, pre-known
0
8421
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
8325
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
8844
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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...
1
8518
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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
4173
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...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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

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.