R
rlvladbob
Hi,
I've try to access a static method using an instance instead of a
class.
public class test{
public static void ShowAText(string ThisText)
{
System.Console.WriteLine("->{0}",ThisText);
}
public static void Main()
{
test.ShowAText("MyText");
}
}
This part work, the call was made using a class (test).
What i need to do, is to call ShowAText using an isntance:
.... Main()
{
test t = new test();
t.ShowAText();
}
This work if I change the ShowAText into a non static method (removing
static keyword).
But then, it's impossible to call it from a non-static call
(test.ShowAText()).
I've try to override it:
public static void ShowAText(string ThisText){...}
public void ShowAText(string ThisText){...}
The compiler refuse since it's a redefinition.
This method can be called from both context since it does not need
class member to run (only a System.Console.WriteLine).
Is there any way arround, except by renaming the function?
I really want to be able to do
.... Main()
{
test t= new test();
t.ShowAText("...");
test.ShowAText("...");
}
Thanks a lot.
Robert
PS: This is an example, my function do much more than just that, but
it's useless to show all my code.
I've try to access a static method using an instance instead of a
class.
public class test{
public static void ShowAText(string ThisText)
{
System.Console.WriteLine("->{0}",ThisText);
}
public static void Main()
{
test.ShowAText("MyText");
}
}
This part work, the call was made using a class (test).
What i need to do, is to call ShowAText using an isntance:
.... Main()
{
test t = new test();
t.ShowAText();
}
This work if I change the ShowAText into a non static method (removing
static keyword).
But then, it's impossible to call it from a non-static call
(test.ShowAText()).
I've try to override it:
public static void ShowAText(string ThisText){...}
public void ShowAText(string ThisText){...}
The compiler refuse since it's a redefinition.
This method can be called from both context since it does not need
class member to run (only a System.Console.WriteLine).
Is there any way arround, except by renaming the function?
I really want to be able to do
.... Main()
{
test t= new test();
t.ShowAText("...");
test.ShowAText("...");
}
Thanks a lot.
Robert
PS: This is an example, my function do much more than just that, but
it's useless to show all my code.