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 6981811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:12:21+00:00 2026-05-27T18:12:21+00:00

I am stuck with this simple looking code for over an hour now… I

  • 0

I am stuck with this simple looking code for over an hour now…
I have few classes…and methods like this:

abstract class ClassBase<SampleInterface> {//Some methods};

public class ClassAction1: ClassBase<MyInterface> {//Some methods};

public class ClassAction2: ClassBase<MyInterface> {//Some methods};

class SomeClass
{ 
    public void AddClassRange(ICollection<ClassBase<MyInterface>> range)
    {
        foreach (ClassBase<MyInterface> ClassBase in range)
            AddClass(ClassBase);
    }


    public void AddClass(ClassBase<MyInterface> behavior)
    {
        // Something
    }
}

Now, I am trying to use these codes in a different class:

var arg1 = new ClassAction1 {//Something};
var arg2 = new ClassAction2 {//Something};

//try1
sampleElement.AddClassRange(new [] { arg1 });   // works fine

//try2
sampleElement.AddClassRange(new [] { arg2 });   // works fine

I want to combine try1 and try2:

// Something like this (try3)
sampleElement.AddClassRange(new [] { arg1, arg2 });   // Error
Error : No best type found for implicitly typed array

As I think, In try1 and try2 runtime is deciding the type for keyword new based on the parameter passed to it. But in try3, parameters are of different types and runtime fails to decide for the best type for the new keyword.

Thanks. Let me know if need more info.

  • 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-05-27T18:12:21+00:00Added an answer on May 27, 2026 at 6:12 pm

    Implicitly typed arrays only work when the type of the array element is the exact compile-time type of one of the elements. In other words, the compiler treats the set of element types as the set of candidate types, and then tries to find exactly one of those types to which all the other types can be implicitly converted.

    In your case, the set of candidate types is ClassAction1 and ClassAction2, neither of which is implicitly convertible to the other – which is why you’re getting a compiler error. So you need to state the desired element type explicitly – presumably ClassBase<MyInterface>:

    sampleElement.AddClassRange(new ClassBase<MyInterface>[] { arg1, arg2 });
    

    Alternatively, you can cast either or both of the elements:

    sampleElement.AddClassRange(new[] { (ClassBase<MyInterface>) arg1, arg2 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been looking into this for a bit now and have become stuck.
I have this idea that using SQL VIEWS to abstract simple database computations (such
I've been stuck with this simple Sql query for last 3 hours and my
I've been struggling with this simple task for more expirienced people, I'm stuck for
This is probably a simple one to answer, but I'm stuck, so here goes.
This seems like a simple question, but I can't find it with the Stack
I'm stuck with this already for some weeks and I don't have the faintest
I have been stuck on this for days, and was wondering if anyone had
This isn't a matter of me being stuck, but rather I'm looking for a
I am stuck with what looks like a simple conceptual issue to me. After

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.