How can I pass, by ref or out parameter values when calling DynamicInvoke
Method.
e.g. Here is my Delegate:
public delegate int BinaryOp(int x, int y, out double z, ref bool overflow);
Here is how I am creating a delegate object for "Subtract" method.
BinaryOp op2 = (BinaryOp) Delegate.CreateDelegate(dt, tt,"Subtract");
Here is how I am creating parameters object[]. Notice t and ret are
variables that I want to pass by ref and out. The following statement works
but ofcourse I am not passing them by ref or value here, so it's giving me
desired results:
object[] param = {3,4,t,ret};
Console.WriteLine(op2.DynamicInvoke(param));
I know I can use invoke method to get solve this issue but I want to see how
can I use DynamicInvoke. e.g. Using invoke it would be:
Console.WriteLine (op2(3,4, out t, ref ret));
Thanks in Advance
Arif 1 8125
Arif,
I don't understand what the problem is. The object array should contain
the modified parameters (assuming they were modified when the method is
called). I just tested it now, and it works fine. If you check the object
array that you passed in, the elements at the indexes for the parameters
that are ref or out will be populated with the changed values (assuming they
are changed).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Arif Khan" <Arif Kh**@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com... How can I pass, by ref or out parameter values when calling DynamicInvoke Method.
e.g. Here is my Delegate: public delegate int BinaryOp(int x, int y, out double z, ref bool overflow);
Here is how I am creating a delegate object for "Subtract" method. BinaryOp op2 = (BinaryOp) Delegate.CreateDelegate(dt, tt,"Subtract");
Here is how I am creating parameters object[]. Notice t and ret are variables that I want to pass by ref and out. The following statement works but ofcourse I am not passing them by ref or value here, so it's giving me desired results:
object[] param = {3,4,t,ret}; Console.WriteLine(op2.DynamicInvoke(param));
I know I can use invoke method to get solve this issue but I want to see how can I use DynamicInvoke. e.g. Using invoke it would be:
Console.WriteLine (op2(3,4, out t, ref ret));
Thanks in Advance Arif This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stephen Johns |
last post by:
I want to have a Hashtable whose keys are strings and whose values are
delegates.
Well, ok, I have that:
dels = new Hastable();
dels.Add( "key", new Foo1Delegate(MyFoo1) );
dels.Add( "key",...
|
by: atwomey |
last post by:
When I try and place a delegate in an interface, like this :
public interface ITest {
double foo();
delegate void bar();
}
I get an error "delegates cannot declare types". What is it about a...
|
by: Bill Woodruff |
last post by:
<
note : this message was sparked in part by comments by David Browne on a
previous thread : "inserting an anonymous method as a value in a generic
dictionary ?" : David had shown the use of...
|
by: =?Utf-8?B?aGVyYmVydA==?= |
last post by:
Jon Skeet wrote in the .NET general newsgroup 11/17/2005:
"The difference between Invoke and DynamicInvoke is that the parameters
to Invoke depend on the delegate itself - the method has the same...
|
by: ohmmega |
last post by:
hello world.
i would like to implement a class with a timer, witch informs me every
second about it's tick. the code works already, but i would like to
change a thing (or more).
<code>
//at...
|
by: Stefan Hoffmann |
last post by:
hi @all,
is there something like an anonymous delegate?
This is the original code:
--
private delegate void DelegateSetFormCaption(string text);
private void SetFormCaption(string text)
{
|
by: Advait Mohan Raut |
last post by:
Hello,
I am using VC# 2005 ; C# 2.0 I am working on the performance
measurement tool. For that I need my code to call user defined method
along with its parameters. For that should I use a...
|
by: puzzlecracker |
last post by:
I've just discovered DynamicInvoke methods while reading Jon's
threading article. And my question is how it's different from a
regular invoke method?
In this method:
/// <summary>
///...
|
by: vcquestions |
last post by:
Hi.
Is there way to have a function pointer to a delegate in c++/cli that
would allow me to pass delegates with the same signatures as
parameters to a method?
I'm working with managed code. ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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: 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,...
| |