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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:15:52+00:00 2026-05-27T12:15:52+00:00

I have an Interface called as IObSrc, I have few classes that implement this

  • 0

I have an Interface called as IObSrc, I have few classes that implement this interface called as ObSrc1, ObScr2 etc..

Interface IObSrc
{
  string id;
}

I also have an interface called as IDtSrc, this interface inturn is implemented by a few classes called as DtSrc1, DtSrc2.

Interface IDtSrc
{
  IObSrc getObject();
  Dictionary<string,IObSrc> getObjects();
}

When i implement this interface from DtSrc1, and I return ObSrc1 from DtSrc1, there is no issue, but when i return Dictionary<string,ObSrc1> or Dictionary<string,ObSrc2>, i get an indication of typemismatch.

public class DtSrc : IDtSrc
{
  public Dictionary<string,IObSrc> getObjects()
  {
    Dictionary<string,ObSrc1> val1 = new ...'
    ...
    return val1;
  }

}

How can i solve this issue.

* EDITED *

I have one more query, what if a method should return a generic type that can be varied by the implementation.

Example:

interface IDtSrc<T> where T:IObSrc
{ 
  T ExecuteObject(string objId);
}

This will be used as

class DtSrc1 
{ 
  string ExecuteObject(string objId)
  {..}
}

and

class DtSrc2
{ 
 Dictionary<string,string> ExecuteObject(string objId)
 {..}
}

Kindly suggest a right procedure for this also.

  • 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-27T12:15:52+00:00Added an answer on May 27, 2026 at 12:15 pm

    You could use generics with a constraint

    interface IDtSrc<T> where T:IObSrc
    {
      IObSrc getObject();
      Dictionary<string,T> getObjects();
    }
    

    But your implementation of IDtSrc will only be able to return one type of IObSrc.

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

Sidebar

Related Questions

I have a property called IsSecureConnection that is part of my object's interface. This
If I have interface IFoo, and have several classes that implement it, what is
I have a bunch of classes that each have a property called Sequence. This
Imagine I have a list of objects that implement an interface called ISummary The
I have an Interface called IStep that can do some computation (See Execution in
I have an interface called Dictionary which has a method insert() . This interface
I have an interface called ICommand from which various classes inherit. These classes all
I have an interface that contains a single method called ListAll() using System.Collections.Generic; namespace
I have a scene, called testScene, it works like this: @interface testScene : myScene
I have made an interface called IHero i implement in my hero.as3 class. the

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.