1 Replies - 3627 Views - Last Post: 12 January 2009 - 10:16 PM Rate Topic: -----

#1 cheesey_toastie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-January 09

Using Enums across multiple classes

Post icon  Posted 12 January 2009 - 02:42 PM

How do I declare an enum so that I can use it in multiple classes?

public enum Sex { Male, Female } 

// in a separate file 
class MyClass {
	public Sex;

	// rest of class
}

// different file

class DifferentClass {

}




Should I use namespaces or some kind of using???

Any help appreciated!



Damn it!

After playing for an hour I finally post a problem then solve it straight away.

I kept the namespaces consistent, removed the duplicated enumeration (I think I had added this in an attempt to get it working) and it works!

Is This A Good Question/Topic? 0
  • +

Replies To: Using Enums across multiple classes

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4424
  • View blog
  • Posts: 12,293
  • Joined: 18-April 07

Re: Using Enums across multiple classes

Posted 12 January 2009 - 10:16 PM

Yeah keep in mind that enums can work at the level of classes. As long as they are public and in the correct namespace, they have a project level visibility just like any other public class has. This is the logical layout not the physical layout where being in a specific file would have mattered.

Glad this is now working for you. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1