I have 2 .cs files each with a class in it. How do I call a method in a class from Form1.cs in another class inside of Form2.cs?
Looks something like this...
Form1.cs
public partial class Class1 : ClassContainer
{
public void awesomeMethod()
{
}
}
Form2.cs
class Class2 : SomethingChanged
{
public void decentMethod()
{
}
}
I would like to call awesomeMethod() inside of the decentMethod(). Thanks.
You can also use the instance of the class to call the public methods of other classes from another class. For example, the method FindMax belongs to the NumberManipulator class, and you can call it from another class Test.
You mean, like this?
public void decentMethod()
{
Class1 instance = new Class1();
instance.awesomeMethod();
}
You need an instance of the class you want to call the method on.
Or, if you don't need/want to work with an instance, make it the method static:
public partial class Class1 : ClassContainer
{
public static void awesomeMethod()
{
}
}
...
public void decentMethod()
{
Class1.awesomeMethod();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With