473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 8471
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**************@TK2MSFTNGP14.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****************@TK2MSFTNGP14.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 ConsoleApplication1

{

/// <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.WriteLine(ex.Message);

}

Console.ReadLine();

}

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
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...
3
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...
0
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...
1
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...
1
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....
0
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...
12
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...
2
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? ...
4
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.