c# class query n methodsGSGaurav Sule12yAsked Aug 6, 2014, 3:04 PM1.5kVisual Basic .NETclass A class B { { void m1() void m2() { { } } in this have to call a method m2 from Class B to Class A.but restriction is dat: no abstract class, abstract method,static,interface,no object creation of class B in A, nested class,constructor,paramtertised contrsctor nothing. no relation betwn A n B n no creation of 3rd class.. no partial obj or class..Only can do is dat make obj in main class bt not in body.n mam told dat codeis of only 3 lines..
Vulpes12y agoPosted Aug 6, 2014, 4:09 PMAccepted answerI didn't entirely follow what you can and can't do here but I'll start the ball rolling with some code:using System;class A{ public void m1() { B b = (B)Activator.CreateInstance(typeof(B)); b.m2(); }}class B{ public void m2() { Console.WriteLine("Hello from B.m2"); }}class Program{ static void Main() { A a = new A(); a.m1(); Console.ReadKey(); }}
Anupam Singh12y agoPosted Aug 7, 2014, 11:11 AMHi Gaurav,I suggest you to study Reflection in .NET and you will find some interesting facts like this..
VulpesPosted Aug 6, 2014, 4:09 PM
Anupam SinghPosted Aug 7, 2014, 11:11 AM
I suggest you to study Reflection in .NET and you will find some interesting facts like this..
Gaurav SulePosted Aug 7, 2014, 11:08 AM