What is the main difference between pointer and delegate with examples?

Questions by sowjanya_polepalli   answers by sowjanya_polepalli

Showing Answers 1 - 5 of 5 Answers

akhilesh kumar srivastava

  • Apr 16th, 2006
 

hi friends this is akhilesh i am answering this question

delegates in c# are very similar to function pointers in c++ the only difference is that delegates are type safe due to these are CLR targated under .net framework, while function pointers in c++ are not type safe.

        A Delegate in c# allows to pass a method of class to object of other class.

Rules in Deligation:-

1.In order to create a Delegate a Signature(parameter) must match Signature of object.

2.Define all the methods which has the same Signature as Deligate define.

3.Create the deligate object & pass the  method as a parameter to Deligate.

4.Now call the encapsulated method using deligated object.

the best example of Deligation modle is ADO.NET Architecture & Event Handling in windows environament.

any confusion then ask me my mail id is  akhi_srivastava2000@yahoo.com

prudhviram

  • Sep 14th, 2006
 

Good answer! but u cant spend your time in giving all that information. Simply say Delegate is a strongly typed function pointer and pointer holds reference to a variable or pointer is a variable which holds the address of another variable.

Fareed

  • Nov 29th, 2006
 

Delegate to function--- is same as---- pointer to object.Delegates are function pointers.They are used when the function which needs to be called is not know at compile time.Pointers, on the other hand, are used to point to variables or object references in unsafe code. Thanx

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions