Reputation: 1082
is there a way to access a method in defferent class with same name space
Sample Codes
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApplication1;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Test()
{
}
}
}
namespace WindowsFormsApplication1
{
public class TestClass
{
public void Test2()
{
}
}
}
I wabt to access test2() method inside Test() method they are in different class but in same namespace i want to access it without instantiating the TestClass class like this
TestClass test = new TestClass();
test.Test2();
i dont want to do it that way is there a way?
NOTE " I am avoiding to use a static Method" thank you for the answering this
Upvotes: 0
Views: 55
Reputation: 709
AS far as I know, there is no way to do it. But why would you want to?
To access Test() you're instantiating a class (Form1). You want then to use a different method but not instantiate the class. So what would be the meaning of running it? What would be its context?
Possible solutions:
Upvotes: 1