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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:52:14+00:00 2026-06-12T07:52:14+00:00

Is it possible to define an interface where one of the objects is a

  • 0

Is it possible to define an interface where one of the objects is a list of another interface?

I have two EF objects:

=====

class ImageType1
{
    string Id
    string Name
    List<ImageType1Size> Sizes
}

class ImageType1Size
{
    string Id
    int Width
    int Height
}

class ImageType2
{
    string UserId
    string ImageId
    string Name
    List<ImageType2Size> Sizes
}

class ImageType2Size
{
    string UserId
    string ImageId
    int Width
    int Height
}

=====

For each of the image size classes, all of the properties are keys (just a side note).

Now, what I want to do is create the following two interfaces:

=====

interface IImage
{
    string Name
    List<ImageSize> Sizes
}

interface IImageSize
{
    int Width
    int Height
}

=====

In my project, I have created partials for ImageType1, ImageType1Size, ImageType2, and ImageType2Size, each using the respective interface.

I’m getting an error in trying to cast the Sizes property in ImageType1 and ImageType2 to use the interface IImageSize.

=====

Is this possible to do? If I’m not clear please let me know and I’ll rephrase the question.

Thanks!

  • 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-12T07:52:15+00:00Added an answer on June 12, 2026 at 7:52 am

    You might want to consider generics here:

    interface IImage<TSize> where TSize : IImageSize
    {
        List<TSize> Sizes { get; }
    }
    
    class ImageType1 : IImage<ImageType1Size>
    {
        List<ImageType1Size> Sizes { get; private set; }
    }
    

    Alternatively, this would work:

    interface IImage
    {
        IEnumerable<IImageSize> Sizes { get; }
    }
    
    class ImageType1
    {
        public List<ImageType1Size> SizeList { get; private set; }
    
        public IEnumerable<IImageSize> Sizes { get { return SizeList; } }
    }
    

    It depends on what works best for how you operate on the data.

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

Sidebar

Related Questions

I have a class which implements the following interface: IUser { string UserName {
Is it possible to define an interface (e.g. MyClass Implements MyInterface) whose method/property definitions
Possible Duplicate: Define a method that has many (or infinite) arguments I have the
It's possible to define an alias in C# like this using kvp = System.Collections.Generic.KeyValuePair<string,
Is it possible to define an instance method in ruby from a string (the
Is it possible in C++ to have two classes, let's call them A and
Is it possible to define an Interface with optional implementation methods? For example I
My project is consisted of two initializations, one init is for the user interface
If an interface inherits IEquatable the implementing class can define the behavior of the
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java

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.