I have the following code, I want to call data1() from data2()
private void data1()
{
}
private static void data2()
{
data1(); //generates error
}
I have the following code, I want to call data1() from data2()
private void data1()
{
}
private static void data2()
{
data1(); //generates error
}
In oder to invoke an non static method you need to create an object.
Static methods are methods on class level. "normal" methods are on object leven.
so what you need to do in order to executer the non static method is the following:
class ClassName {
private static void data2() {
var data1Obj = new ClassName();
data1Obj.data1();
}
private void data1() {
//execute code here
}
}
but if you only use data1 in this way you could make that static to