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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:39:09+00:00 2026-05-10T20:39:09+00:00

In C# I sometimes wish I could make special methods for certain instantiations of

  • 0

In C# I sometimes wish I could make special methods for certain ‘instantiations’ of generic classes.

UPDATE: The following code is just a dumb example of a more abstract problem – don’t focus too much on time series, just the principles of ‘adding extra methods’ for certain T.

Example:

class Timeseries<T>  {      ...     TimeSeries<T> Slice(...) { ... } } 

In the case where T is double, I would like some extra methods, like Integrate(), Interpolate() and so on that make only sense for double, because I need to do arithmetic on them.

There are several ways to do this, but I cannot find one that I’m satisfied with.

1. Inherit into a special class

class TimeseriesDouble : Timeseries<double> {      double Interpolate(...) { ... }     ... } 

cons: TimeseriesDouble.Slice() will return a new Timeseries<double> object, now missing my special methods.

2. External methods

public static double Interpolate(Timeseries<double> ts, ...) { ... } 

cons: Breaks with OO principles. And I don’t want to put my methods away. Also, the methods might need private/protected state.

3. Extension methods

Same as 2, just with a nicer calling syntax.

4. Common base class

class TimeSeries_base { ... } class TimeSeries<T> : TimeSeries_base { .. typesafe versions of methods .. } class TimeSeriesDouble : TimeSeries_base { .. typesafe versions of methods .. } 

cons: too much duplication of things from TimeSeries_base into the two subclasses. The base class might become just a place holder for utility functions for the sub classes.

pro: I can now do things like List<TimeSeries_base> dynamically.

5. Just forget about a common class

I.e., keep Timeseries<T> and TimeseriesDouble separate in the code.

cons: Then I don’t get all the benefit of treating a TimeseriesDouble like a TimeSeries<T>, e.g. combining two timeseries with ZIP(A,B), where one happens to be of doubles.


Any other ideas? Currently, I think I like the design (1) best.

  • 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. 2026-05-10T20:39:10+00:00Added an answer on May 10, 2026 at 8:39 pm

    You could always use the self-referential generics trick:

    public class TimeSeries<T, U> where U : TimeSeries<T, U> {     U Slice(...) }  public class TimeSeriesDouble : TimeSeries<double, TimeSeriesDouble> {     ... } 

    It can get a bit brain-bending, but it can work.

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

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You cannot pass command line arguments to the JUnit test… May 11, 2026 at 12:21 pm
  • added an answer Clearly this is a major undertaking which will involve lots… May 11, 2026 at 12:21 pm
  • added an answer Represent all food for which you collect data as a… May 11, 2026 at 12:21 pm

Related Questions

I'm using a native DLL (FastImage.dll) in a C# ASP.NET Web Service that sometimes
in C# I'd like to invoke the label edit of a newly added item
I'll preface this by saying that I usually work in C#/.Net. Normally, I use
I'm developing a LoB application in Java after a long absence from the platform

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.