class that does not need to be instantiated

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

I have a public class myClass that has public emum state...

public class myClass
{
public emum state {bind=0, noBind=1, etc... };
static myClass{}
}

I want to be able to access the state enum without having to instantiate
myClass in the code..
I just want to be able to access myClass.state.bind etc...

I believe there is a key word that I need to use in the declaration of
myClass..

Thanks,
Jerry
 
Prefix your enum with static

Eg.

public class myClass
{
static public enum Things
{
Something,
SomethingElse,
AnotherThing
}
}

You can then access this enumerator through myClass.Things without
instantiating the class.

Hope this helps,

Mun
 
You're right about the keyword, but you need to use it on your class MEMBERS
you want to call without having to instantiate the class:

public class myClass
{
static public emum state {bind=0, noBind=1, etc... };
}
 
public class ControlStates

{

static public enum PageMode {DetailEdit = 0, DetailView = 1, ListEdit = 2,
ListView = 3, ListDetail = 4, NoAccess = 5};

static public enum ControlState {Enabled = 0, Disabled = 1, ReadOnly = 2,
Hidden = 3};

static public enum ControlStateSetBy {DBSecurity = 0, PageModeSecurity = 1,
DeveloperSecurity = 2};

static IControlStates()

{

//

// TODO: Add constructor logic here

//

}

}



This is giving me a compile error that "modifier static is not valid for
this item"

Jerry
 
Don't use the static word on your enumeration.


public class ControlStates

{

public enum PageMode

{

DetailEdit = 0, DetailView = 1, ListEdit = 2,

ListView = 3, ListDetail = 4, NoAccess = 5};

public enum ControlState

{

Enabled = 0, Disabled = 1, ReadOnly = 2,

Hidden = 3};

public enum ControlStateSetBy

{

DBSecurity = 0, PageModeSecurity = 1,

DeveloperSecurity = 2};

}

This code works. You can do ControlStates.PageMode.DetailEdit directly
without intantiate the class.
 
All enums ARE static already.

The syntax myClass.Things.SomethingElse is usable statically
 
Yep, you're right. I stand corrected. :-)

Cheers,

Mun



Eric Newton said:
All enums ARE static already.

The syntax myClass.Things.SomethingElse is usable statically


--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(e-mail address removed)-software.com [remove the first "CC."]

Munsifali Rashid said:
Prefix your enum with static

Eg.

public class myClass
{
static public enum Things
{
Something,
SomethingElse,
AnotherThing
}
}

You can then access this enumerator through myClass.Things without
instantiating the class.

Hope this helps,

Mun
 
i dont use c#, but in visual Basic.NET, you must used "shared": for example:

class Myclass
shared value as string
shared function mysum(byval X as integer) as integer
return value + x
end function
end class

so, you dont need to use instance of this class.
its possible use this in C#??? (i dont know)

And sorry my english, please!!! (im spanish)


Jakala

end class
 
yip, only difference is instead of "shared", use "static" (and of course
proper C# syntax)

i still dont understand why the VB team, in all their wisdom, decided to
change keywords:
Shared = static
MustInherit = abstract
NotInheritable = sealed

why, vb guys, why? marketing! ...er, yea?
 
Back
Top