Our team is creating a new recruitment workflow system to replace an old one. I have been tasked with migrating the old data into the new schema. I have decided to do this by creating a small Windows Forms project as the schema are radically different and straight TSQL scripts are not an adequate solution.
The main sealed class 'ImportC...
Suppose I have two applications written in C#. The first is a third party application that raises an event called "OnEmailSent".
The second is a custom app that I've written that I would like to somehow subscribe to the "OnEmailSent" even of the first application.
Is there any way that I could somehow attach the second application to a...
In C#, what is the difference (if any) between these two lines of code?
tmrMain.Elapsed += new ElapsedEventHandler(tmrMain_Tick);
and
tmrMain.Elapsed += tmrMain_Tick;
Both appear to work exactly the same. Does C# just assume you mean the former when you type the latter?
...
What is the difference between a delegate and an event? Don't both hold references to functions to be executed?
...
What are some real world places that call for delegates? I'm curious what situations or patterns are present where this method is the best solution. No code required.
...
Haven't fired up reflector to look at the difference but would one expect to see the exact same compiled code when comparing Func<T, bool> vs. Predicate<T>
I would imagine there is no difference as both take a generic parameter and return bool?
...
Does the Java language have delegate features, similar to how C# has support for delegates?
...
How would you dynamically subscribe to a C# event so that given a Object instance and a String name containing the name of the event, you subscribe to that event and do something (write to the console for example) when that event has been fired?
It would seem using Reflection this isn't possible and I would like to avoid having to use R...
I'm using C#.
So I have an object which has some fields, doesn't really matter what.
I have a generic list of these objects.
List<MyObject> myObjects = new List<MyObject>();
myObjects.Add(myObject1);
myObjects.Add(myObject2);
myObjects.Add(myObject3);
So I want to remove objects from my list based on some criteria.
For instance, ...
This is from an example accompanying the agsXMPP .Net assembly. I've read up on delegates, but am not sure how that fits in with this line of code (which waits for the logon to occur, and then sends a message. I guess what I'm looking for is an understanding of why delegate(0) accomplishes this, in the kind of simple terms I can unders...
Conceptually, I would like to accomplish the following but have had trouble understand how to code it properly in C#:
SomeMethod { // Member of AClass{}
DoSomething;
Start WorkerMethod() from BClass in another thread;
DoSomethingElse;
}
Then, when WorkerMethod() is complete, run this:
void SomeOtherMethod() // Also mem...
Suppose we have:
interface Foo
{
bool Func(int x);
}
class Bar: Foo
{
bool Func(int x)
{
return (x>0);
}
}
class Baz: Foo
{
bool Func(int x)
{
return (x<0);
}
}
Now we can toss around Bar and Baz as a Foos and call their Func methods.
Delegates simplify this a little bit:
delegate bool Foo(int x);
bool Bar...
Several Linq.Enumerable functions take an IEqualityComparer<T>. Is there a convenient wrapper class that adapts a delegate(T,T)=>bool to implement IEqualityComparer<T>? It's easy enough to write one (if your ignore problems with defining a correct hashcode), but I'd like to know if there is an out-of-the-box solution.
Specifically, I wa...
One thing I am concerned with is that I discovered two ways of registering delegates to events.
OnStuff += this.Handle;
OnStuff += new StuffEventHandler(this.Handle);
The first one is clean, and it makes sense doing "OnStuff -= this.Handle;" to unregister from the event... But with the latter case, should I do "OnStuff -= new StuffE...
With the advent of new features like lambda expressions (inline code), does it mean we dont have to use delegates or anonymous methods anymore? In almost all the samples I have seen, it is for rewriting using the new syntax.
Any place where we still have to use delegates and lambda expressions won't work?
...
Backstory: I'm using log4net to handle all logging for a project I'm working on. One particular method can be called under several different circumstances -- some that warrant the log messages to be errors and others that warrant the log messages to be warnings.
So, as an example, how could I turn
Public Sub CheckDifference(ByVal A As...
I want to create a list of methods to execute. Each method has the same signature.
I thought about putting delegates in a generic collection, but I keep getting this error:
'method' is a 'variable' but is used like a 'method'
In theory, here is what I would like to do:
List<object> methodsToExecute;
int Add(int x, int y)
{ retur...
This is clearly not appears like it wouldn't be a best practice, but can someone explain why or how this works. Or recommend a good book to learn more.
//The constructor
public Page_Index() {
//create a local value
string currentValue = "This is the FIRST value";
//use the local variable in a delegate that fires later
...
Take the following c# class:
c1 {
event EventHandler someEvent;
}
If there are a lot of subscriptions to c1's 'someEvent' event and I want to clear them all, what is the best way to achieve this? Also consider that subscriptions to this event could be/are lambdas/anonymous delegates.
Currently my solution is to add a ResetSubscriptio...
I am using boost::signal in a native C++ class, and I now I am writing a .NET wrapper in C++/CLI, so that I can expose the native C++ callbacks as .NET events. When I try to use boost::bind to take the address of a member function of my managed class, I get compiler error 3374, saying I cannot take the address of a member function unless...