473,699 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to change variable value which is using as param list in sub functoin

I need to set several variable (can be different type) by sub
function..
I don't know the count of variable and type, so i used object type and
parameter list like below source..
After setData function call a1,a2 is still -1 and "AAA"
I want to be change as 3,"BBB"
Does anybody can help me???

class Program
{
static void Main(string[] args)
{
int a1 = -1;
string a2 = "AAA";
setData(a1,a2);
}

public void setData(params object[] list)
{
list[0] = 3;
list[1] = "BBB;
}
}

Jun 7 '07 #1
5 1807
<ct*****@gmail. comwrote:
I need to set several variable (can be different type) by sub
function..
I don't know the count of variable and type, so i used object type and
parameter list like below source..
After setData function call a1,a2 is still -1 and "AAA"
I want to be change as 3,"BBB"
Does anybody can help me???
You need to pass the parameters by reference (the ref modifier).
However, you can't do that with parameter arrays (the params keyword).

See http://pobox.com/~skeet/csharp/parameters.html for more
information.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 7 '07 #2
On 6 7 , 3 31 , Jon Skeet [C# MVP] <s...@pobox.com wrote:
<cty0...@gmail. comwrote:
I need to set several variable (can be different type) by sub
function..
I don't know the count of variable and type, so i used object type and
parameter list like below source..
After setData function call a1,a2 is still -1 and "AAA"
I want to be change as 3,"BBB"
Does anybody can help me???

You need to pass the parameters by reference (the ref modifier).
However, you can't do that with parameter arrays (the params keyword).

Seehttp://pobox.com/~skeet/csharp/parameters.html for more
information.

--
Jon Skeet - <s...@pobox.com >http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
A

Jun 7 '07 #3
Thanks for your help..

Actually what i want to do is that communication between two class.
One is sending message with datas (serveral message)
The other is catching message and set variable with included message
from sender...

According to http://pobox.com/~skeet/csharp/parameters.html
Parameter arrays allow only variable number of arguments but I need
reference argument...
It there any other solution???

Please help me :=)

Jun 7 '07 #4
A params array is (broadly) syntactic sugar for a regular array, and
since arrays are reference types, if contents are edited in place the
values will remain edited to the caller; "ref" here would just allow
you to *reassign* the array, which isn't what you want.

Unfortunately you need to use regular array syntax to make this work,
but it can be done as below. However, my advice is to represent the
values in a class; this gives you far better context, i.e. you don't
have to remember that index 8 is the forename and should be a string -
you have a "string Forename" property.

object[] values = {3, "abc"};
SomeFunc(values );
object arg0 = values[0]; // will be 7
object arg1 = values[1]; // will be "Fred"

....
private void SomeFunc(object[] args) {// could be "params", but
doesn't help any
args[0] = 7;
args[1] = "Fred";
}

<ct*****@gmail. comwrote in message
news:11******** **************@ o11g2000prd.goo glegroups.com.. .
Thanks for your help..

Actually what i want to do is that communication between two class.
One is sending message with datas (serveral message)
The other is catching message and set variable with included message
from sender...

According to http://pobox.com/~skeet/csharp/parameters.html
Parameter arrays allow only variable number of arguments but I need
reference argument...
It there any other solution???

Please help me :=)

Jun 7 '07 #5
On Jun 7, 8:26 am, cty0...@gmail.c om wrote:
Actually what i want to do is that communication between two class.
One is sending message with datas (serveral message)
The other is catching message and set variable with included message
from sender...
I can't say I like this as a design, personally. I think it would be
much more straightforward to encapsulate the parameters either into a
mutable type, or let the method take one set of parameters and return
its result in a return value (either of the same type or a different
one).

Reference parameters are generally harder to read and use, IMO.

Jon

Jun 7 '07 #6

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

Similar topics

1
2705
by: Eric Wagar | last post by:
I have a phpnuke website, and I use DigiChat chat. Since I have users who register, I'd like to be able to pass there username and email (at a minimum) into the chat system, so they do not have to enter in their information multiple times. I am attempting to use the below file (which was obtained from a website using DigiChat and something called IBForums), but I am not able to get any output on the page when using it. Any help? ...
4
12531
by: Richard Davies | last post by:
Hi I have a ASP and SQL Server website which uses a couple of Stored Procedures during the Shopping Cart process. 1 inserts the Customer information into a table and the next inserts the Payment information into a table. I don't have access to the code now, but have found that many of our customers, especially those who use I.E 6 are having problems with a
10
5529
by: Clay_Culver | last post by:
I have heard that it is possible to use classes + template magic to make standalone functions (or maybe just a functor which acts like a function) which can accept variable length arguments without using the elipse. For example, a funciton could take in 1 known type, then a variable list of other parameters: ReturnValueClass rvc = someFunction("Some known type", 1, 0.2, "string"); ReturnValueClass rvc2 = someFunction("Some known type...
1
7622
by: richardscheff | last post by:
Video selector works for IE but not other browsers. for not IE <object ID='Player' data="video/dodgeball.wmv" type="video/x-ms-wmv" width="320" height="280"> <param name="filename" value="video/dodgeball.wmv" /> <param name="ShowControls\" value="1" /> <param name="AutoStart\" value="1" /> <param name="PlayCount\" value="1" />
4
1856
by: msnews.microsoft.com | last post by:
hello every one i am using media player in internet explorer but i cannot access it directly in code behind, so do you know a way to access it? <object id="video123" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" runat="server"> <param name="URL" value="mms://srv-enterprise/site_diffusion/( hi want to add a value here !!!!!!!!! )"/> <param name="SendPlayStateChangeEvents" value="True"/> <param...
15
2790
by: bcochofel | last post by:
Hi, I want to use a variable to sort elements. That var his passed with query string (I'm using Perl CGI to generate XML). Here's a sample of my output: --------------------------------------------- <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xml" href="RR.xsl"?> <!-- $Id: template.xml,v 1.5 2006/12/11 11:13:30 bcochofel Exp $ --> <RR xmlns:xsi="http://www.w3.org/2001/XMLSchema"...
3
5613
by: Skip | last post by:
OK, I'm a novice in JS but have lots of coding experience. I am trying to accomplish something that would seem somewhat simple - BUT IT'S NOT. I have a basic window that calls another window with window.open and passes in 1 value using a querystring i.e., www.myhome.com/mypage?video=BAK-Extension Now when the window opens, I can capture the passed value in a JS function. But if I want to use that in the body of the HTML in a
8
12618
by: Jeff | last post by:
Still new to vb.net in VS2005 web developer... What is the proper/standard way of doing the following - setting the value of a variable in one sub and calling it from another? E.g., as below. The code below draws an error as indicated. Surely there has to be a better way than to make xxx a session variable? Thanks
4
3100
by: Zachary Turner | last post by:
Let's say I have a variable defined as follows: <xsl:variable name="test_variable_1" value="'test_value_A'"/> <xsl:variable name="test_variable_2" value="'test_value_B'"/> <xsl:variable name="test_variable_3" value="'test_value_C'"/> Then, somewhere else in my source document I have some elements like this: <some-doc-element param="2"/>
0
8685
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
8613
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
9032
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
8908
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
8880
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...
1
6532
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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();...
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
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.