Accessing Enums from another class C#

techmanbd

Junior Contributor
Joined
Sep 10, 2003
Messages
397
Location
Burbank, CA
Here is the following code. I have a class, and access it in my main form.

Part of my class comGPIB
C#:
public class comGPIB
	{
		Board brd = new Board();
		Device devdev = new Device(0,0);
		public int iHELLO;
		public Device [] devGPIB = new Device[5];
		public bool boolPSConnected;
		public enum Dev {PS=0, AGSwitch1=1, AGSwitch2=2, KeithleyMM=3};// Used for which array for devGPIB
		public enum PS {Agilent=0,Xantrex=1}; //Used when for which Power Supply is found on the GPIB Network
}

And here is the code from my main form

C#:
comGPIB cGPIB = new comGPIB();// this is up at the top where my variables are

	private void btnPractice_Click(object sender, System.EventArgs e)
		{
			
			string readIt = cGPIB.readGPIB(cGPIB.devGPIB[1]);			
			this.lblPract.Text = readIt;
		}

When I do cGPIB. in the drop down box I can see the public integer and the public boolean variable, but not the enums I created.

Now when I do this I see it and it work, by putting the namespace.
C#:
int i = HBAS_PVFT_Rack.comGPIB.Dev.AGSwitch1;

Is there an explanation for this? I tried reading the help files and didn't see anything on why I need the namespace for the enum in that class.

Thanks,
 
Thanks, yes I do see other little bugs, as when I am typing the index cursor stays in one spot while the letters are being typed. At first I kept thinking I hit something for it to go back. Unfortunatley I don't have the luxury of my company getting the latest. Plus I won't be working here too much longer as they are closing the facility and moving to China. Maybe my next job I can get the newer version.
 
I think the issue here is that in one case you are trying to access the enum through a variable (cGPIB), and in the other case you are accessing the enum through the type (comGPIB). The enum is not a member of the class. It is a nested type.
 
Back
Top