I was reading the Essential C# 3.0 book and am wondering if this is a good way to check delegates for null?:
class Thermostat
{
public delegate void TemperatureChangeHandler ( float newTemperature );
public TemperatureChangeHandler OnTemperatureChange { get; set; }
float currentTemperature;
public float CurrentTempera...
In this question Jon Skeet offered a very interesting solution to making a LINQ-to-XML statement dynamic, but my knowledge of lambdas and delegates is not yet advanced enough to implement it:
I've got it this far, but of course I get the error "smartForm does not exist in the current context":
private void LoadWithId(int id)
{
XDoc...
I can't be the only one getting tired of defining and naming a delegate for just a single call to something that requires a delegate. For example, I wanted to call .Refresh() in a form from possibly other threads, so I wrote this code:
private void RefreshForm()
{
if (InvokeRequired)
Invoke(new InvokeDelegate(Refresh));
...
OK, I've tried but I just don't get it.
I have two classes logger and class1.
I have a method called logger.Write(string) and method called class1.Execute().
Now in my application I want to have logger.Write(class1.ToString()) run when class1.Execute() is called.
I presume you need to add delegates and events, but I just can't get my...
It's my understanding that if I want to get the ID of an item in a list, I can do this:
private static void a()
{
List<string> list = new List<string> {"Box", "Gate", "Car"};
Predicate<string> predicate = new Predicate<string>(getBoxId);
int boxId = list.FindIndex(predicate);
}
private static bool getBoxId(string item)
{
...
I have the following code for population a ListView from a background thread (DoWork calls the PopulateThread method):
delegate void PopulateThreadCallBack(DoWorkEventArgs e);
private void PopulateThread(DoWorkEventArgs e)
{
if (this.InvokeRequired)
{
PopulateThreadCallBack d = new PopulateThreadCallBack(this.PopulateTh...
I've taken some stuff from Apple's QUartzDemo project and am trying to modify it.
I want to create a screen with a button that will then call the rest of the stuff to make the rectanlges from that demo.
I've created a UIViewController that handles my initial view. It has a start button on it. The start button code is:
- (IBAction)st...
I create a UIViewController with a button on it. The button's only job is to create a window for drawing some rectangles. (I've taken some code from "QuartzDemo" from Apple's example applications.) Objective C is really giving me fits...
When I try this, nothing happens.
Here's the code for the button:
- (IBAction)startButtonAct:(i...
How?
The following did not work:
delegate MyDelegate;
ref class MyDelegate;
delegate void MyDelegate;
The following works for declaration:
public delegate void MyDelegate(Object ^sender, MyArgs ^args);
But using it as a forward declaration gives me
error C3756: 'MyNameSpace::MyDelegate': delegate definition conflicts with an exi...
Why can't you pass an anonymous method as a parameter to the BeginInvoke method ? I have the following code:
private delegate void CfgMnMnuDlg(DIServer svr);
private void ConfigureMainMenu(DIServer server,)
{
MenuStrip mnMnu = PresenterView.MainMenu;
if (mnMnu.InvokeRequired)
{
mnMnu.Begin...
I want to have a generic event that I can fire that will take a custom eventArgs> e
Here is my code so far
public event resultsEventHandler<T> returnResults;
public delegate void resultsEventHandler<T>(object sender, resultEventArgs<ObservableEntityCollection<T>> e);
protected virtual void OnreturnResults(resultEventArgs<ObservableE...
I'm on the verge of madness ...
In the application I'm actually building, I'm dealing with two dynamically-added controls that need to interact with each other, but I've reduced the problem to an as-simple-as-I-can-make-it example with the controls being statically loaded, and it still presents the same problem: a NullReferenceException...
Suppose I have a class that represents a product to be priced using one of a number of different pricing strategies. This pricing occurs hundreds of times per second, so to eliminate repetitive if/else statements I am instead using a delegate to launch the appropriate strategy, like so:
Private Delegate Sub PricingModel(ByVal params As ...
Extension methods can be assigned to delegates that match their usage on an object, like this:
static class FunnyExtension {
public static string Double(this string str) { return str + str; }
public static int Double(this int num) { return num + num; }
}
Func<string> aaMaker = "a".Double;
Func<string, string> doubler = FunnyExtensio...
My solutions has several projects which includes several libraries and one project for UI. Currently it is a windows forms application and I use log4net for logging. This UI project has only reference to log4net and this project maintains the configuration files. But I would like to log from my libraries as well.
Usual method for doing...
There is a question already answered which is http://stackoverflow.com/questions/32034/in-c-isnt-the-observer-pattern-already-implemented-using-events
It asks if the observer pattern is already implemented in c# using events.
While I get the events and observer pattern, isn't the observer pattern really just delegates and events is a f...
I have two methods in C# 3.5 that are identical bar one function call,
in the snippet below, see clientController.GetClientUsername vs clientController.GetClientGraphicalUsername
private static bool TryGetLogonUserIdByUsername(IGetClientUsername clientController, string sClientId, out int? logonUserId)
{
string userna...
Hello. I found something quite odd(I think!). If I try to put a breakpoint in the yes() method, it will never pause the program when it executes the function. If I try to do the same to any other line of code, it will work just as expected. Is it a bug, or is there something that's escaping me?
The filter will return the 2 objects, ever...
I have a WCF web service that currently searches multiple, hard-coded dtSearch indices and then merges the resulting datasets to be returned back to the client. I have the following C# code:
public class Search : ISearch
{
delegate DataTable PDelegate(string term, int cid);
delegate DataTable CDelegate(string term, int sid);
...
Does anyone know where I can find a good explanation/tutorial of what and how an application delegate works in objective-C? The two books I have don't dwell on delegates enough and do not explain them very well for me to truly understand their power and function.
...