accessing public static member of one class in another class
-
Hi, i need to access public static member of one class into another class. please provide the help. Learning c#. Ex: class ABC { static int nEllipsecount = 0; // in some function increment nEllipseCount; }; // class xyz in another file class ABC; class xyz { if(ABC :: nEllipseCount >0) { //Process these statements; } }; i couldn't be able access static value into to another class. is my approach wrong ? Please help me to resolve. Thanks & Regards, Royal
-
Hi, i need to access public static member of one class into another class. please provide the help. Learning c#. Ex: class ABC { static int nEllipsecount = 0; // in some function increment nEllipseCount; }; // class xyz in another file class ABC; class xyz { if(ABC :: nEllipseCount >0) { //Process these statements; } }; i couldn't be able access static value into to another class. is my approach wrong ? Please help me to resolve. Thanks & Regards, Royal
First, as you've shown it,
nEllipsecount
is NOT public. In c# the default is private. So, what you seem to want is:class ABC
{
public static int nEllipsecount = 0; // made it public
// in some function increment nEllipseCount;}
// class xyz in another file
class xyz
{// below presumably in a method...
if (ABC.nEllipseCount >0) // syntax for reference to class static
{
//Process these statements;}
}
If it isn't made public then you can't see it from
xyz
at all. (Unless it isprotected
and you inherit fromABC
.)A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
-
Hi, i need to access public static member of one class into another class. please provide the help. Learning c#. Ex: class ABC { static int nEllipsecount = 0; // in some function increment nEllipseCount; }; // class xyz in another file class ABC; class xyz { if(ABC :: nEllipseCount >0) { //Process these statements; } }; i couldn't be able access static value into to another class. is my approach wrong ? Please help me to resolve. Thanks & Regards, Royal
Your code is hinting that you're working with C++ and not C#. Is this true??
A guide to posting questions on CodeProject
How to debug small programs
Dave Kreskowiak -
Hi, i need to access public static member of one class into another class. please provide the help. Learning c#. Ex: class ABC { static int nEllipsecount = 0; // in some function increment nEllipseCount; }; // class xyz in another file class ABC; class xyz { if(ABC :: nEllipseCount >0) { //Process these statements; } }; i couldn't be able access static value into to another class. is my approach wrong ? Please help me to resolve. Thanks & Regards, Royal
-
First, as you've shown it,
nEllipsecount
is NOT public. In c# the default is private. So, what you seem to want is:class ABC
{
public static int nEllipsecount = 0; // made it public
// in some function increment nEllipseCount;}
// class xyz in another file
class xyz
{// below presumably in a method...
if (ABC.nEllipseCount >0) // syntax for reference to class static
{
//Process these statements;}
}
If it isn't made public then you can't see it from
xyz
at all. (Unless it isprotected
and you inherit fromABC
.)A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
Thanks alot Matt,
public static int nEllipsecount = 0; // made it public
In the above statement I'm declaring the static member in public only, kindly tell me any other way i can declare as public. Thanks & Regards, Royal
-
Thanks alot Matt,
public static int nEllipsecount = 0; // made it public
In the above statement I'm declaring the static member in public only, kindly tell me any other way i can declare as public. Thanks & Regards, Royal
You can't declare a public member/method/class etc, with anything other than the public keyword. C# requires explicit scope declaration if you're trying to do anything other than declare something as private, which is the default scope. What are you trying to achieve because using a
public static
is generally not a good idea?