When building classes I thought if I just added an enum to the parameter list it would pop up the list of the enums, sort of like intellisence.. But I clearly am missing something..

public enum eFullWeekDays
        {
            Sunday = 1,
            Monday = 2,
            Tuesday = 3,
            Wednesday = 4,
            Thursday = 5,
            Friday = 6,
            Saturday = 7,

        }
 
       public DateTime PrevDayofWeek(DateTime datepassed, eFullWeekDays FullWeekDay,bool subtractWeekIfPassCorrectDay)
        {
:
:
}

Only has the intellisense if I do the following

dteNewDate = GenDates.PrevDayofWeek(testdate, (GeneralDates.eFullWeekDays)intWKDay, boolIFCorrectDay);

or

dteNewDate = GenDates.PrevDayofWeek(testdate, GeneralDates.eFullWeekDays.Thursday, boolIFCorrectDay);

Anyway to get it to pop up the weekday list without the prefix of GeneralDates.efullweekdays????

Dani AI

Generated

Short answer: modern C# lets you bring enum members into scope so IntelliSense will show the values without typing the enum type. For older C# you either qualify the enum (what you saw) or place the enum at namespace scope so it is easier to reference.

Example (C# 6+):

using static System.DayOfWeek;

// later in the file
DayOfWeek d = Thursday;

The using static directive imports the enum members so the editor will offer Thursday, Friday, etc., without DayOfWeek.. See the C# using static docs for details: .

Design and scope notes tied to the thread:

  • As commented, avoid Hungarian-style prefixes like e — follow .NET naming rules (PascalCase, no type prefixes) to keep code readable and discoverable; see the Naming Guidelines.
  • If the enum is nested inside a class (your GeneralDates.eFullWeekDays), the outer type must be part of the qualifier unless you change its scope to namespace level. demonstrated the scoping behavior; moving the enum out of the class reduces the qualifier length.

Troubleshooting and cautions:

  • using static is available in C# 6 and later; it can introduce name collisions, so use it sparingly.
  • If IntelliSense does not show candidates, try Ctrl+Space (or Ctrl+J), verify the project builds, confirm the enum is public and referenced, and check Tools→Options→Text Editor→C#→IntelliSense.
  • If targeting older compilers, the only reliable choices are qualifying the enum or changing its declaration scope.

Recommended Answers

All 5 Replies

What the fuck are you naming your enum type "eFullWeekDays" for and not "FullWeekDays"? Unless you have actual evidence that prefixing your variables with the names of their types increases your productivity, you are just a superstitious nutjob.

Anyway to get it to pop up the weekday list without the prefix of GeneralDates.efullweekdays????

No, because you could also theoretically type in a variable of type GeneralDates.eFullWeekDays.

Just a newbie with an incredible learning curve. C#, asp.net, java, html, Linq, AJAx.... etc etc.. Yes at this point you could call me a nutjob from overload..

Since I name the enum in the library and then have to call it in the calling programs it is just helping my overloaded brain. Rather then guessing if I call it Weekday, FullWeekday, DaysOfTheWeek.etc.. Right now the e... helps me get to the list of enums I created and figure out what I need, and helps me seperate them from the long list of objects and properties in the library..

Sorry if my code is offensive, but right now the need is to learn and accomplish.. Quickly...

Sorry, I was just being a jerk :)

You will have to write the name of the enum's type in order to trigger autocomplete; that's life.

There is a System.DayOfWeek enumeration.
There is a DateTime structure with a property DayOfWeek which returns this enumeration.
So why would you feel the need to make your own?
.Net is HUGE, perhaps you did not know it existed?
Join the club, I had the same experience already...

ddanbe beat me to it. I'd go with the System.DayOfWeek, however to answer the general enum question, you would only need the GeneralDates if the eFullWeekDays enum instance is outside the scope of your class or namespace.

Example:

namespace TestA
{
    public class Class1
    {
        public enum Values
        {
            Val1,
            Val2,
            Val3
        }
    }
}
namespace TestB
{
    public class Class2
    {
        public Class2()
        {
            // have to use namespace and class path
            TestA.Class1.Values.Val1;
        }
    }
}

If you bring it out one level, then you have:

namespace TestA
{
    public enum Values
    {
        Val1,
        Val2,
        Val3
    }
    public class Class1
    {

    }
}
namespace TestB
{
    public class Class2
    {
        public Class2()
        {
            // have to use namespace path
            TestA.Values.Val2;
        }
    }
}

Or if it's in the same namespace:

namespace TestA
{
    public enum Values
    {
        Val1,
        Val2,
        Val3
    }
    public class Class1
    {

    }
    public class Class2
    {
        public Class2()
        {
            // same namespace, nothing but enum is needed
            Values.Val3;
        }
    }
}

Intellisense works in all scenarios....

-Nelis

commented: Clear explanation, well done. +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.