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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:46:59+00:00 2026-05-25T19:46:59+00:00

I have a class such as: public MyClass { public myEnumType Status {get;set;} public

  • 0

I have a class such as:

public MyClass
{
   public myEnumType Status {get;set;}
   public DataTable Result{get;set;}
}

Because DataTables suck I want to implement an object orientated approach. However I have existing code such as:

public interface IData
{
  MyClass AddData(int i);
  MyClass GetData(string Tablename);
}

I would like to use this interface but instead of returning a DataTable I want to return an object of some sort eg/Person class.

I did think of creating a new class that inherited MyClass like so:

public MyInheritedClass<T> : MyClass
{
  public new T Result{get;set;}
}

However whenever you get data from a class that implements the interface you will have to cast the result of the methods from MyClass to MyInheritedClass. So I was wondering if there was a way of using the existing MyClass to put a constructor in that passes a generic type so I end up with something like

public MyClass
{
   public MyClass(T MyObjectOrientatedClass)
   {
      MyOOClass = MyObjectOrientatedClass;
   }
   public myEnumType Status {get;set;}
   public DataTable Result{get;set;}
   public T MyOOClass {get;set;}
}
  • 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-25T19:47:00+00:00Added an answer on May 25, 2026 at 7:47 pm

    In C#, the types of expressions are determined by the types of their constituent pieces at compile time. This means something like your last example (where the type of the property is unknowable just by knowing the type of the class) can’t work.

    Imagine if that class definition compiled. Then you have this problem:

    // What would you use as the type of this variable?
    ??? val = GetMyClassFromSomewhere().MyOOClass;
    

    Sure you could use object, but then you wouldn’t know anything about the property value, so you’d have to cast before you could do anything with it anyway.


    Addressing your original issue, it is possible (with a few rough edges) to extend your existing types in a compatible fashion by deriving a new generic interface from your existing IData interface:

    public interface IData<T> : IData
    {
        new MyInheritedClass<T> AddData(int i);
        new MyInheritedClass<T> GetData(string Tablename);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class: public class MyClass<T> { public string TestProperty { get; set;
If I have a simple class such as:- @XmlRootElement public class MyClass { @XmlAttribute(required=true)
I have such class public unsafe class EigenSolver { public double* aPtr {get; private
I have such a class: public class Cycle { public List<int> Edges { get;
In AS3, if I have a class such: public class dude { //default value
If I have a base class such that public abstract class XMLSubscription <T extends
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
Let's say I have a regular simple Java class, such as: public class Foo
Say I have a simple object such as class Something { public int SomeInt
So let's say we have a domain object such as the following public class

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.