.NETGURU
Defing an Enum in C#
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Steve Mark
-- Moved from [aspngfreeforall] to [aspngcs] by Victor Von Doom <Click here to reveal e-mail address> --

We're stumped.

We'd like to create an enumeration like MS does with SqlOleDbType but
for cursor types (in this case). We would like to be able to write
this:

    Public CursorType Cursor
    {
        set {m_cursorType = value;}
        get {return m_cursorType;}
    }

Where CursorType is defined as:

    enum CursorType : int
    {
        wait = 1,
        arrow = 2,
        crosshair = 3
    }

Therefore this can be called as:

    Object.CursorType = CursorType.wait;

The problem is that the enum has to be defined in a class, such as:

    class Globals
    {
        public enum CursorType : int
        {
            wait = 1,
            arrow = 2,
            crosshair = 3
        }
    }

So we have to use the syntax:

    Object.CursorType = Globals.CursorType.wait;

The problem is that we'd like to get rid of the "Globals." prefix. This
could be solved by allowing the enum to be defined at the namespace
level, but we can't do this.

Does anyone know how we can do this or if this is even doable?

Steve

Reply to this message...
 
    
James Shaw (VIP)
Of course, by adding a..

using YourNamespace.Globals;

..to your code, you do "hide" the Globals namespace just like MS does with
SqlOleDbType. That's what I've accepted as the only way to do that.

(by the way, Globals seems far too generic a description. Surely
YourCompanyName.Cursors would be better for that?)

James Shaw
http://CoverYourASP.com/
Download it. Run it. Learn it.
http://ASPRSS.com/
Publish ASP with RSS XML

-----Original Message-----
From: Steve Mark [mailto:Click here to reveal e-mail address]
Sent: Thursday, August 15, 2002 7:42 PM
To: aspngcs
Subject: [aspngcs] Defing an Enum in C#

-- Moved from [aspngfreeforall] to [aspngcs] by Victor Von Doom
<Click here to reveal e-mail address> --

We're stumped.

We'd like to create an enumeration like MS does with SqlOleDbType but
for cursor types (in this case). We would like to be able to write
this:

Public CursorType Cursor
{
set {m_cursorType = value;}
get {return m_cursorType;}
}

Where CursorType is defined as:

enum CursorType : int
{
wait = 1,
arrow = 2,
crosshair = 3
}

Therefore this can be called as:

Object.CursorType = CursorType.wait;

The problem is that the enum has to be defined in a class, such as:

class Globals
{
public enum CursorType : int
{
wait = 1,
arrow = 2,
crosshair = 3
}
}

So we have to use the syntax:

Object.CursorType = Globals.CursorType.wait;

The problem is that we'd like to get rid of the "Globals." prefix. This
could be solved by allowing the enum to be defined at the namespace
level, but we can't do this.

Does anyone know how we can do this or if this is even doable?

Steve
| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Richard Lowe
Why can't you define your enum in the namespace? - enums can be declared in
namespaces legally:

using System;

namespace test
{
enum CursorType : int
{
        wait = 1,
        arrow = 2,
        crosshair = 3
}
}

works just fine. It there some design issue you have with this?

Richard

--- Steve Mark <Click here to reveal e-mail address> wrote:
[Original message clipped]

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

Reply to this message...
 
    
Steve Mark
Great, we'll give it a try.

And yes, we are prefixing namespaces with a company name and a level or
two more before we actually get to a class name. I shortened what we
are doing for this example.

Thanks again!

Steve

-----Original Message-----
From: James Shaw [mailto:Click here to reveal e-mail address]
Sent: Thursday, August 15, 2002 5:56 PM
To: aspngcs
Subject: [aspngcs] RE: Defing an Enum in C#

Of course, by adding a..

using YourNamespace.Globals;

..to your code, you do "hide" the Globals namespace just like MS does
with SqlOleDbType. That's what I've accepted as the only way to do that.

(by the way, Globals seems far too generic a description. Surely
YourCompanyName.Cursors would be better for that?)

James Shaw
http://CoverYourASP.com/
Download it. Run it. Learn it.
http://ASPRSS.com/
Publish ASP with RSS XML

-----Original Message-----
From: Steve Mark [mailto:Click here to reveal e-mail address]
Sent: Thursday, August 15, 2002 7:42 PM
To: aspngcs
Subject: [aspngcs] Defing an Enum in C#

-- Moved from [aspngfreeforall] to [aspngcs] by Victor Von Doom
<Click here to reveal e-mail address> --

We're stumped.

We'd like to create an enumeration like MS does with SqlOleDbType but
for cursor types (in this case). We would like to be able to write
this:

Public CursorType Cursor
{
set {m_cursorType = value;}
get {return m_cursorType;}
}

Where CursorType is defined as:

enum CursorType : int
{
wait = 1,
arrow = 2,
crosshair = 3
}

Therefore this can be called as:

Object.CursorType = CursorType.wait;

The problem is that the enum has to be defined in a class, such as:

class Globals
{
public enum CursorType : int
{
wait = 1,
arrow = 2,
crosshair = 3
}
}

So we have to use the syntax:

Object.CursorType = Globals.CursorType.wait;

The problem is that we'd like to get rid of the "Globals." prefix. This
could be solved by allowing the enum to be defined at the namespace
level, but we can't do this.

Does anyone know how we can do this or if this is even doable?

Steve
| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Steve Mark
That actually worked fine and is exactly what we need. We must have
been doing something wrong before. Thanks!

Steve

[Original message clipped]

Reply to this message...
 
 
System.Object




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification