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

The Archive Base Latest Questions

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

I have been battling with this for a while, so any help would be

  • 0

I have been battling with this for a while, so any help would be appreciated. Here’s the scenario i am faced with on C# .NET 4.0.

public interface ITableBusinessLogicLayerIn<in TTableRecord> : IBusinessLogicLayer
    where TTableRecord : ITableRecord
{
// No definition
}

public interface ITableBusinessLogicLayerOut<out TTableRecord> : IBusinessLogicLayer
    where TTableRecord : ITableRecord
{
// No definition
}

I have an object which implements both interfaces. Code compiles fine. But at runtime, I am able to cast this object as follows:

(ITableBusinessLogicLayerOut<ITableRecord>)obj

but not as this:

(ITableBusinessLogicLayerIn<ITableRecord>)obj

This is highly confusing, i’m not sure what i am doing wrong. Someone please point me in the right direction. 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-05-21T06:47:13+00:00Added an answer on May 21, 2026 at 6:47 am

    Contravariance (in) allows you to cast an object with a type parameter of a less-specific type to one of a more-specific type. For example, you can’t pass an object to a type the expects a string, so you can’t cast a type that expects a string to a type that expects an object. See here for more information: http://msdn.microsoft.com/en-us/library/ee207183%28d=lightweight%29.aspx

    Given the following example:

    class MyTableRecord : ITableRecord { }
    ITableBusinessLogicLayerIn<ITableRecord> inA;
    ITableBusinessLogicLayerIn<MyTableRecord> inB;
    ITableBusinessLogicLayerOut<ITableRecord> outA;
    ITableBusinessLogicLayerOut<MyTableRecord> outB;
    

    You can assign inB to inA, but not the reverse. You can assign outA to outB, but not the reverse.

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

Sidebar

Related Questions

I've been battling this one for a while now. I have a stored proc
I have been battling with this code for quite a while and just don't
Hey I have been battling with this problem for a while now. Perhaps there
I have been battling with this piece of code for literally days now... Would
I've been battling to get this right...basically I have the following HTML setup: <div
I've been battling with this issue for a couple of days now. I have
Have been trying to fix this problem I have here. Basically I have a
So I have been battling this issue for awhile now and tried many different
Hi I have been battling with this issue all day. I have a vs2010
So, I've been battling with Javascript for a little while now and I 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.