Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:38:37+00:00 2026-06-08T03:38:37+00:00

This may be a basic question, but I googled it and didn’t find an

  • 0

This may be a basic question, but I googled it and didn’t find an answer. I hope you will help me. Consider I have an enum ContactNumberType:

string[] names = Enum.GetNames(typeof(ContactNumberType))

If I use the above, the compiler gives no error, but when I write:

string[] names = Enum.GetNames(ContactNumberType)

It says:

ContactNumberType is a type but used like a variable.

While the type of ContactNumberType is Enum, as far as I know, and the argument of method GetNames needs EnumType, so whats the issue with that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:38:38+00:00Added an answer on June 8, 2026 at 3:38 am

    You have to use typeof becuase the GetNames() method takes a parameter of type Type. Keep in mind that providing a type name is not the same as an instance of Type, which is an object that contains the details of that type.

    To pass a type as a parameter, you have two basic choices:

    • Pass a Type instance
    • Use a generic

    The first of these (which many older methods such as Enum.GetNames() does) requires you to get a Type instance from the type identifier, which we can do using the typeof() operator.

    The second of these allows you to pass a type name as a parameter to a method or class to make that method or class generic and tends to be used on newer methods (generics were introduced in .NET 2.0):

    var items = someList.OfType<SomeTypeName>();
    

    Enum, however, doesn’t have a generic form of GetNames() that allows this, though you could create something like one:

    public static class EnumHelper
    {
        public static string[] GetNames<T>() where T : struct
        {
            return Enum.GetNames(typeof(T))
        }
    }
    

    Which you could then call like:

    string[] names = EnumHelper.GetNames<ContactNumberType>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a basic question, but I could not find an answer for
This may be a basic question but the answer has alluded me so far.
I know this may be a basic question but I cannot find a basic
This may be a basic question, but I'm still looking for the answer. I've
This may be a basic question, but is it possible to have colon (:)
this may seem like a very basic question, but i have difficulty grasping it,
This may be a basic question but how can I include a module with
This may seem a basic question but my is not currently working. I am
This may seem like a realy basic question but... How do you use double
This may seem like a basic question. I have a light-weight website and would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.