C# public variables problem
This is a noob question
using System.name;
class class_name
{
private className Obj;
public class_name()
{
}
public function()
{
Obj.function <----- why i cant acesss the global varible here ??
}
}
When i type the class the instellisence docent show any thing :开发者_JS百科-s
I'm assuming there was just some confusion with the names and, by function
, you meant class_name
, or instead of class_name
you meant className
.
In order to access a method this way, it must be declared as static. Otherwise, you must first create an instance of the class and access the method through the instance.
EDIT The code you posted is very confusing. The following works just fine for me.
class Class1
{
public void Function1()
{
}
}
class Class2
{
private Class1 obj;
public void Function2()
{
obj.Function1();
}
}
Have you instantiated that class?
精彩评论