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

  • SEARCH
  • Home
  • 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 7785319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:14:11+00:00 2026-06-01T20:14:11+00:00

I have a method that would like to take as parameter an array of

  • 0

I have a method that would like to take as parameter an array of Custom Enum types.

Something that would look like this:

public void DoSomething(WhatDoIPutHere[] parameters)

I would like to pass to this method either a Enum1[] or a Enum2[] where Enum1 and Enum2 are 2 Enum types.

What do I need to use instead of WhatDoIPutHere ?

I would have expected to define the signature of DoSomething as Enum[] as somehow Enum is the base class for Enum types (right?) :

public void DoSomething(Enum[] parameters)

but it gives a :

cannot convert from ‘xxx.Enum1[]’ to ‘System.Enum[]’

I also tried defining it as object[] but I get the same kind of compiler error..

I know this is totally smelly code, and if I could I would definitely get rid of it …

  • 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-01T20:14:12+00:00Added an answer on June 1, 2026 at 8:14 pm

    You can’t. Value type arrays aren’t covariant. You sort of want to write:

    public void DoSomething<T>(T[] parameters) where T : struct, System.Enum
    

    … but that’s not allowed either (type parameters can’t be constrained to be enums or delegates).

    Options:

    • Allow any array:

      public void DoSomething(Array parameters)
      
    • Allow any array of value types:

      public void DoSomething<T>(T[] parameters)
      
    • Use Unconstrained Melody to write the first form, via IL-rewriting hack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HtmlHelper extension method that I would like to apply some logic
I have a script with a factory method that I would like to return
I have a static method in my code that I would like somehow to
I have an activity that launches another activity with startActivityForResult method. I would like
Is there builtin method that would do this or do I always have to
I have a WCF service with many methods. I would like that after executing
I have a private method def __pickSide(self): in a parent class that I would
I have this method that changes an larger image source on click. I need
What types and arguments does the method, Any when using Expression.Call take? I have
I have a junit test method that takes a CommonsMultipartFile object as a parameter.

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.