473,385 Members | 1,154 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,385 software developers and data experts.

more about event and delegete

Hello!

Class CharChecker has a field that is called TestChar that is of type event
CharEventHandler.
I know that if I change in method foo so I have
tester.TestChar +=new CharEventHandler(Testing);
it work so you don't have to mention that.

I have a reason for this testing so it has a value for me.
I wonder if it's possible to send this TestChar that is of type event
CharEventHandler
from Main in my example to another method in my case it's foo.

I can understand that what I'm doing seems rather strange but I just want to
know if it's possible.

I think you understand when you look at my code to see what I'm trying to
do.
using System;
public delegate void CharEventHandler(object source, CharEventArgs e);

public class CharEventArgs : EventArgs
{
public char CurrChar;

public CharEventArgs( char CurrChar )
{
this.CurrChar = CurrChar;
}
}

public class CharChecker
{
private char curr_char;
public event CharEventHandler TestChar;

public char Curr_Char
{
get { return curr_char; }
set
{
if (TestChar != null)
{
CharEventArgs args = new CharEventArgs(value);
TestChar(this, args);
curr_char = args.CurrChar;
}
}
}
}

public class MyApp
{
private void foo(CharEventHandler arg, CharChecker tester)
{
tester.arg +=new CharEventHandler(Testing);
tester.Curr_Char = 'T';
}
public static void Main()
{
CharChecker tester = new CharChecker();
foo(tester.TestChar, tester );
}
static void Testing(object source, CharEventArgs e)
{
Console.WriteLine("Testing");
}
}

//Tony


Aug 18 '06 #1
0 850

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: Scott David Daniels | last post by:
Over on comp.python.education we were discussing a (generally seen as) misuse of decorators to build the definite integral of a function. On thinking over the definite integral decorator, I had...
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
4
by: Peter Lin | last post by:
Dear all; I need to monitor a xml file so that I can update my data in hashtable, but the problem is it will trigger more than one event for a lastwrite action(I trigger this action by add...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
22
by: Colin McGuire | last post by:
I apologize for posting yet another scrollbar question. Here is my code. All I want is for a diagonal line to appear from coordinates (0,0) to (width,height) in a usercontrol regardless of whether...
3
by: tony | last post by:
Hello! My problem is that I have several methods that is quite similar. Each one works as they should. You see two of them just below. I have removed several statements that is not relevant for...
5
by: ShaunO | last post by:
BACKGROUND I have the following classes as part of a program that opens 3 Asynchronous Sockets. Each socket is in a separate instance of a wrapping class. 1x User Interface class 1x Client...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.