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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:13:42+00:00 2026-05-16T18:13:42+00:00

Suppose you have an interface like this: public interface IDoSomething<out T> { T DoSomething(object

  • 0

Suppose you have an interface like this:

public interface IDoSomething<out T>
{
    T DoSomething(object value);
}

To be able to call DoSomething on that interface without knowing the type of T, you have to create this:

public interface IDoSomething
{
    object DoSomething(object value);
}

Modify your original interface to inherit from the new one:

public interface IDoSomething<out T> : IDoSomething
{
    new T DoSomething(object value);
}

And then do this:

((IDoSomething)obj).DoSomething();

”’But”’ then you have to implement the DoSomething method on your implementation twice; once explicitly and once implicitly.

One solution that partly works is to do this:

((IDoSomething<object>)obj).DoSomething();

But this only works if the generic type is a reference type; value types like DateTime and int won’t work, even though they too inherit from object. Why is this?!

Is there a solution to this conundrum yet (without employing abstract classes!)?

  • 1 1 Answer
  • 2 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-16T18:13:43+00:00Added an answer on May 16, 2026 at 6:13 pm

    Well value types are not supported.

    Implication and the reason behind, as far as I know, mainly involves the difference in storage of arrays.

    Let’s imagine we have:

    Byte[] bb = new Byte[20];
    byte b = 255;
    bb[0] = b; // here value is copied into the array
    b = 128;
    Console.WriteLine(bb[0]); // will print 255
    

    So changing the b does not change the value we have assigned and this is expected.
    But what if we do something like this:

    object[] bb = new Byte[20]; // throws exception
    

    System treats object arrays differently and stores the pointer and not the value. We actually have only one type of object array (from the structure point of view not type) and that is pointer array while arrays for value types store the value.

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

Sidebar

Related Questions

Suppose I have this annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Name { String value(); }
Suppose I have a few definitions like so: public interface ICategory { int ID
Suppose a construct like this: class Interface { public: template <typename T> virtual void
Suppose I have an interface for a service: public interface IFooService { void DoSomething();
Suppose I have this: @Transactional(rollbackFor = NotificationException.class) public interface PersonManagerService { public void addPerson(Person
Let's say I have a service whose interface is something like this: public interface
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose I have this: public class Unit<MobileSuit, Pilot> { ... List<MobileSuit> mobileSuits; List<Pilot> pilots;
Let's suppose I have a struct like this: struct my_struct { int a; int

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.