I am having a weird situation with a behavior of this class, and I am not understanding the reason.
Could you please help me?
I have this Class Teste.cs:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespaceRMAFF.Engine
{
publicclassTeste
{
publicintTesteFunction()
{
int teste = 10;
return teste;
}
}
}
And I am trying to access the function TesteFunction() in this other class Teste2.cs, but no success. I can access the class Teste, but I can't access the public function TesteFunction.
rohit kumar3 reputationPosted Jun 30, 2010, 2:19 AM EDT
0
yes this will work..
because your method ,you have called in 2nd class is not staitc thats why can't be accessed by class name,
to do so either make an object of teste() class or put static KW with your method definition...
Daniel Varghese14 reputationPosted Jun 23, 2010, 10:47 AM EDT
The above class is not accessible because you have not instantiated the class.
Please try the below code to see if it works,
namespace RMAFF.Engine { class Teste2 { void caramba() { Teste myclass = new Teste(); myclass.TesteFunction(); [your class will be accesible now]}
}
}
To directly access your method without instantiating the class use static keyword in your function declaration.
Hope this clears your doubts.
Thanks,
Daniel
rohit kumar3 reputationPosted Jun 30, 2010, 2:19 AM EDT
because your method ,you have called in 2nd class is not staitc thats why can't be accessed by class name,
to do so either make an object of teste() class or put static KW with your method definition...