KH  Cheong

KH Cheong

  • NA
  • 1
  • 637

What is the use of having "ref" in this case

May 19 2015 10:15 PM
Hi, 
 
I came across a question which made me confused. What is the use of having "ref" before s.MyFun in this case. I tried to remove it and it still works. 
 
I understand the reason for putting it before a variable that the content can be changed subsequently. What is the use of this one ? the function content will not be changed.  
 
class Sample 
{    
   public void MyFun(int i, Single j)     
   {         
       Console.WriteLine("Welcome to IndiaBIX !");     
}
delegate void del(int i, Single j); 
del d; Sample s = new Sample(); 
d = new del(ref s.MyFun); 
d(10, 1.1f);
 
 

Answers (1)