void and static void problem
-
Dear all, is is possible to call a static method from a non-static method and the other way around eg.:
private void Test1()
{
Test2();
}private static void Test2()
{
//some stuff here
}The example above will generate an error, but I would like to know if , and how it can be done. Thank you for any assistance. Kind regards,
-
Dear all, is is possible to call a static method from a non-static method and the other way around eg.:
private void Test1()
{
Test2();
}private static void Test2()
{
//some stuff here
}The example above will generate an error, but I would like to know if , and how it can be done. Thank you for any assistance. Kind regards,
Do you know how to call static methods from outside the class where it is defined? You can call it in the same way. If not then it means that you are not familiar with static methods so why do you use it? As for second question you will need an instance of a class that defines nonstatic method.
Giorgi Dalakishvili #region signature my articles My blog[^] #endregion
-
Dear all, is is possible to call a static method from a non-static method and the other way around eg.:
private void Test1()
{
Test2();
}private static void Test2()
{
//some stuff here
}The example above will generate an error, but I would like to know if , and how it can be done. Thank you for any assistance. Kind regards,
-
Within the same class, an instance method can call a static, but a static cannot call an instance.
unless you pass an instance reference to it...
-Spacix All your skynet questions[^] belong to solved
I dislike the black-and-white voting system on questions/answers. X|
-
Dear all, is is possible to call a static method from a non-static method and the other way around eg.:
private void Test1()
{
Test2();
}private static void Test2()
{
//some stuff here
}The example above will generate an error, but I would like to know if , and how it can be done. Thank you for any assistance. Kind regards,
The only way to do this is to have your Test2 method have an instance of the class as a parameter or make one available to it in some other way.