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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:49:54+00:00 2026-05-26T13:49:54+00:00

So I have a basic class that inherits an interface as below public interface

  • 0

So I have a basic class that inherits an interface as below

public interface IRefDataItem
{
    int RefID { get; set; }
string Code { get; set; }
}

public class RACodeItem : IRefDataItem
{
    public int RefID { get; set; }
    public string Code { get; set; }
}

I then have a method that return a List of RACodeItem which I am attempting to assign to a List of IRefDataItem as below

List<IRefDataItem> codes = GetRACodes( ); //GetRACodes returns List of RACodeItem 

I’m getting an error here stating that cannot implicitly cast type List of RACodeItem to List of IRefDataItem, despite the fact that RACodeItem inherits IRefDataItem

Am I missing something simple here? How can I cast a List of T to a List of an interface type that T implements?

Cheers

Stewart

  • 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-26T13:49:55+00:00Added an answer on May 26, 2026 at 1:49 pm

    I understand why you are trying this but if you think about you will realise this can’t work.

    For example (This code won’t compile)

    public interface ITest
    {
    }
    
    public class Test1 : ITest
    {
    }
    
    public class Test2 : ITest
    { }
    
    
    static void Main(string[] args)
    {
        List<ITest> list = new List<Test1>();
    
        list.Add(new Test1());
        list.Add(new Test2());
    
    }
    

    The problem is you can’t add Test2 to a List of Test1. Declaring you list as List<ITest> list = new List<ITest>(); will compile and you can add both Test1 and Test2.

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

Sidebar

Related Questions

I have a basic class that derived subclasses inherit from, it carries the basic
I have a very basic data class that is subclassed from NSObject. I declare
the basic idea is that you have some class that has a reference type
Basic C# syntax question: So I have this class public class BrandQuery<T> : Query<T>
Say I have a couple of basic objects like so: [Serializable] public class Base
I have an extended GridView class, GridViewEx, which inherits from the basic ASP.NET gridview.
i have a basic ruby class: class LogEntry end and what i would like
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
i have a really basic java program just one .java/.class file (.java uncompiled .class
My current class is planning on creating a basic networked game, but we have

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.