Can anyone tell me why this code behaves the way it does? See comments embedded in the code...
Am I missing something really obvious here?
using System;
namespace ConsoleApplication3
{
public class Program
{
static void Main(string[] args)
{
var c = new MyChild();
c.X();
Conso...
I'm writing code like this, doing a little quick and dirty timing:
var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000; i++)
{
b = DoStuff(s);
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Surely there's a way to call this bit of timing code as a fancy-schmancy .NET 3.0 lambda rather than (God forbid) cutting ...
Working on a project where a sequential set of methods must be run every x seconds. Right now I have the methods contained within another "parent method", and just sequentially call them right after another.
class DoTheseThings()
{
DoThis();
NowDoThat();
NowDoThis();
MoreWork();
AndImSpent();
}
Each method must ru...
After looking on MSDN, it's still unclear to me how I should form a proper predicate to use the Find() method in List using a member variable of T (where T is a class)
For example:
public class Car
{
public string Make;
public string Model;
public int Year;
}
{ // somewhere in my code
List<Car> carList = new List<Car>();...
I am experimenting with calling delegate functions from a delegate array. I've been able to create the array of delegates, but how do I call the delegate?
public delegate void pd();
public static class MyClass
{
static void p1()
{
//...
}
static void p2 ()
{
//...
}
//...
static pd[]...
My app has a DataGridView object and a List of type MousePos. MousePos is a custom class that holds mouse X,Y coordinates (of type "Point") and a running count of this position. I have a thread (System.Timers.Timer) that raises an event once every second, checks the mouse position, adds and/or updates the count of the mouse position on t...
Hello,
In a piece of C# that I am writing at the moment I need to handle several methods with the same signature in the same way. Also there might be more of these methods in the future. Instead of repeating the same kind of logic over and over I thought up the following:
private delegate bool cleanStep(BuildData bd, out String strFail...
Hello there,
what's the best/proper way of interacting between several windows in C# app?
Recently, I've run into a problem where one of program windows has to call method modifying main window. My solution was to create factory-like class, that would arrange all underlying model-data and organize the communication between various wind...
I'm writing Application A and DLL B, both in C#.NET. How do I do the following:
A calls function in B
Want B to use delegate/callback to update status in UI of A
This is not about BackgroundWorker...that part works fine in A. What I can't see is how to let B know what function to call in A.
...
Hi,
Are delegates the same thing as callbacks? Or are they related somehow?
...
In a code review, I stumbled over this (simplified) code fragment to unregister an event handler:
Fire -= new MyDelegate(OnFire);
I thought that this does not unregister the event handler because it creates a new delegate which had never been registered before. But searching MSDN I found several code samples which use this idiom.
So...
I have a delegate, say:
public delegate void MyDelegate();
I have an event, say:
public MyDelegate MyEvent;
While invoking the event I am receiving an error message:
"MyEvent += expected ....."
How do I resolve this?
...
Once it is compiled, is there a difference between:
delegate { x = 0; }
and
() => { x = 0 }
?
...
I'm looking to implement the Observer pattern in VB.NET or C# or some other first-class .NET language. I've heard that delegates can be used for this, but can't figure out why they would be preferred over plain old interfaces implemented on observers. So,
Why should I use delegates instead of defining my own interfaces and passing arou...
Does using delegates slow down my programs?
I've been avoiding them because I really have no clue if they make my programs any slower. I know if I cause a (catch) exception, that uses quite a bit of CPU power but I don't know about Delegates and Events and what .NET does to them.
...
Delegates look like such a powerful language feature, but I've yet to find an opportunity to use them in anger (apart from in DALs I must say).
How often do you use them, and under what circumstances do you find them most useful?
...
I have been going back and forth between C# and Java for the last 8 years.
One thing that strikes me is that I have completely stopped using the "Template Method" design pattern in C#. Actually, in C# I Have come to think of this pattern as an anti-pattern.
http://en.wikipedia.org/wiki/Template_method_pattern
Coming back to Java, I ...
I am trying to determine the best directory structure of my application
i have:
UI
Data
Interfaces
but i dont know where to put delegates..
should there be a seperate Delegates folder or should i store the delegates in the same classes where they are being used . .
...
Hi,
Sorry if this is basic but I was trying to pick up on .Net 3.5.
Question: Is there anything great about Func<> and it's 5 overloads? From the looks of it, I can still create a similar delgate on my own say, MyFunc<> with the exact 5 overloads and even more.
eg: public delegate TResult MyFunc<TResult>() and a combo of various overl...
It seems that I can't control the NSApp delegate from within a System Preferences pane, which is understandable. Is there any other way I can have my object notified when the program becomes active?
...