Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionComo reproducir 2 videos sin cuadros negros entre ellos Pin
Member 1117759324-Nov-14 4:07
Member 1117759324-Nov-14 4:07 
AnswerRe: Como reproducir 2 videos sin cuadros negros entre ellos Pin
den2k8824-Nov-14 4:17
professionalden2k8824-Nov-14 4:17 
QuestionPDF ti HTML Pin
nitin_ion23-Nov-14 23:38
nitin_ion23-Nov-14 23:38 
AnswerRe: PDF ti HTML Pin
Richard MacCutchan24-Nov-14 0:17
mveRichard MacCutchan24-Nov-14 0:17 
QuestionC sharp Delegate Pin
Sarita S23-Nov-14 22:30
Sarita S23-Nov-14 22:30 
AnswerRe: C sharp Delegate Pin
Kornfeld Eliyahu Peter23-Nov-14 22:53
professionalKornfeld Eliyahu Peter23-Nov-14 22:53 
AnswerRe: C sharp Delegate Pin
Pete O'Hanlon24-Nov-14 0:11
mvePete O'Hanlon24-Nov-14 0:11 
AnswerRe: C sharp Delegate Pin
hassan faghihi24-Nov-14 1:17
professionalhassan faghihi24-Nov-14 1:17 
delegate are anonymous methods, same to what you do with lambda expression, before lambda it were available on begin C# versions....

So, you can do several thing through this:

1. Generate a new method inside an other method, once you need it, like:
Thread t = new Thread(new ThreadStart(delegate(){ ... } ) );
t.Start();

as you see 'delegate(){..}' is equal to the longer version of lambda; ()=>{...}

2. the other use is to pass a method to a function, That's same to what MethodInvoker do for concurrent programming, on win form application, which if you don't you may cause cross-thread exception.

if (this.InvokeRequired)
{
Invoke(new MethodInvoker(delegate()
{
...
}));
}

,
so you may come to a place where you write a method, which need something right in middle of code which you don't know, and the user may need to choose what code should be run...

so you define a delegate function (mean you give it a name and sets its signature)
then you use that as a input parameter, so you can use that function reference to call the function, user provide for you:

here is a sample:

public delegate int MyInvoker(int a, int b);

public void MyMethod(MyInvoker operation, int a, int b)
{
int result = operation(a, b);
}

Then the user may call your method like this:

MyMethod( (a,b)=>a+b, 1, 2);

or this:

private void sum(int a, int b)
{
return a+ b;
}

MyMethod(sum, 1, 2);

or may he use a deleagate:
delegate (a,b){return a+b}
as the input parameter.

NOTE: ThreadStart is a delegate too, it's same to MethodInvoker, i just tried to make different sample .
GeneralRe: C sharp Delegate Pin
Sarita S24-Nov-14 2:35
Sarita S24-Nov-14 2:35 
QuestionCapturing Data from an Excel Spreadsheet Pin
JimmyMac9123-Nov-14 11:45
JimmyMac9123-Nov-14 11:45 
AnswerRe: Capturing Data from an Excel Spreadsheet Pin
PIEBALDconsult23-Nov-14 12:23
mvePIEBALDconsult23-Nov-14 12:23 
GeneralRe: Capturing Data from an Excel Spreadsheet Pin
JimmyMac9123-Nov-14 16:01
JimmyMac9123-Nov-14 16:01 
GeneralRe: Capturing Data from an Excel Spreadsheet Pin
Mycroft Holmes23-Nov-14 18:27
professionalMycroft Holmes23-Nov-14 18:27 
Questionrunning FTP Server Pin
Janis Heller23-Nov-14 8:52
Janis Heller23-Nov-14 8:52 
QuestionRe: running FTP Server Pin
PIEBALDconsult23-Nov-14 9:27
mvePIEBALDconsult23-Nov-14 9:27 
AnswerRe: running FTP Server Pin
Janis Heller23-Nov-14 9:45
Janis Heller23-Nov-14 9:45 
GeneralRe: running FTP Server Pin
Pete O'Hanlon23-Nov-14 20:51
mvePete O'Hanlon23-Nov-14 20:51 
QuestionObject reference not set to an instance of an object on passing reference variable to WPF Forms! Pin
EngrKhizarIqbal23-Nov-14 7:07
EngrKhizarIqbal23-Nov-14 7:07 
AnswerRe: Object reference not set to an instance of an object on passing reference variable to WPF Forms! Pin
Dave Kreskowiak23-Nov-14 7:33
mveDave Kreskowiak23-Nov-14 7:33 
AnswerRe: Object reference not set to an instance of an object on passing reference variable to WPF Forms! Pin
4a616e23-Nov-14 23:13
4a616e23-Nov-14 23:13 
GeneralRe: Object reference not set to an instance of an object on passing reference variable to WPF Forms! Pin
EngrKhizarIqbal24-Nov-14 7:51
EngrKhizarIqbal24-Nov-14 7:51 
Questionredirect webtraffic without writing rules to HOSTS file Pin
Janis Heller23-Nov-14 5:48
Janis Heller23-Nov-14 5:48 
AnswerRe: redirect webtraffic without writing rules to HOSTS file Pin
Dave Kreskowiak23-Nov-14 7:31
mveDave Kreskowiak23-Nov-14 7:31 
AnswerRe: redirect webtraffic without writing rules to HOSTS file Pin
Bernhard Hiller24-Nov-14 4:47
Bernhard Hiller24-Nov-14 4:47 
QuestionHow to retrive user name from Master Page control (Lable) and Display in aspx page using c# Pin
Member 785476923-Nov-14 4:24
Member 785476923-Nov-14 4:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.