troubleshooting Question

C# main class instance

Avatar of JRumana
JRumana asked on
Programming Languages-OtherC#
4 Comments1 Solution1242 ViewsLast Modified:
I have a doubt in the following code why we have to create the instance

of the same class like below

TestDelegateClass tdc = new TestDelegateClass();

in the given code.

My doubt is we have to create instance if there are two classes but here are having only one class
Please clarify me..



public delegate Boolean MyDelegate(Object sendingobj, Int32 x);
 
public class TestDelegateClass
{     
	Boolean MyFunction(Object sendingobj, Int32 x) 
	{           
		//Perform some processing           
		return (true);  
	}
	       
	public static void main(String [] args)
	{
		//Instantiate the delegate passing the method to invoke in its constructor
		MyDelegate mdg = new MyDelegate(MyFunction);
            
		// Construct an instance of this class
		TestDelegateClass tdc = new TestDelegateClass();
               
		// The following line will call MyFunction
		Boolean f = mdg(this, 1);
       
	}
}
ASKER CERTIFIED SOLUTION
CyrexCore2k

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros