How to use +, -, *, / etc in C# Generic - CSharp

This is a discussion on How to use +, -, *, / etc in C# Generic - CSharp ; Question is how to make the following class compile? class foo<T> { private T a, b; public T Sum() { return a + b; // this line does not compile. } } The background is that I want this class ...

+ Reply to Thread
Results 1 to 4 of 4

How to use +, -, *, / etc in C# Generic

  1. Default How to use +, -, *, / etc in C# Generic

    Question is how to make the following class compile?

    class foo<T>
    {
    private T a, b;

    public T Sum()
    {
    return a + b; // this line does not compile.
    }
    }

    The background is that I want this class to be instantiated by all the
    "numeric friendly" classes (i.e. those support operator like +,
    - ...). These should include both built-in types, (e.g. double) and
    user defined class.

    Thanks.

  2. Default Re: How to use +, -, *, / etc in C# Generic

    As I stated previously - if you are using .NET 3.5 I can fix this for
    you instantly; let me know if this is an option.
    If not, it is a major PITA.

    Previous post: http://groups.google.com/group/micro...ac16748fa115e5

    Marc

  3. Default Re: How to use +, -, *, / etc in C# Generic

    On Fri, 14 Dec 2007 15:39:34 -0800, My interest <myinterest@gmail.com>
    wrote:

    > Question is how to make the following class compile?
    >
    > class foo<T>
    > {
    > private T a, b;
    >
    > public T Sum()
    > {
    > return a + b; // this line does not compile.
    > }
    > }


    Didn't we just have this thread? Didn't you start that one too?

    Hint: just because the operator is now + instead of *, that doesn't make
    it a new question.

  4. Default Re: How to use +, -, *, / etc in C# Generic

    On Dec 14, 7:00 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
    wrote:
    > On Fri, 14 Dec 2007 15:39:34 -0800, My interest <myinter...@gmail.com>
    > wrote:
    >
    > > Question is how to make the following class compile?

    >
    > > class foo<T>
    > > {
    > > private T a, b;

    >
    > > public T Sum()
    > > {
    > > return a + b; // this line does not compile.
    > > }
    > > }

    >
    > Didn't we just have this thread? Didn't you start that one too?
    >
    > Hint: just because the operator is now + instead of *, that doesn't make
    > it a new question.


    Sorry, this is a repost. My explorer crashed right after I clicked
    the Submit button. So I assumed it failed to post. Sorry about the
    re-posting.

+ Reply to Thread

Similar Threads

  1. when using generic
    By Application Development in forum vhdl
    Replies: 10
    Last Post: 11-07-2007, 04:48 PM
  2. Copy Items from a Generic List into multiple Generic Lists
    By Application Development in forum CSharp
    Replies: 5
    Last Post: 10-12-2007, 12:27 PM
  3. Replies: 1
    Last Post: 03-28-2007, 02:05 PM
  4. Dynamic generic type with base generic type definition
    By Application Development in forum DOTNET
    Replies: 2
    Last Post: 11-11-2006, 08:38 AM
  5. Stack overflow calling from generic method to non-generic method.
    By Application Development in forum DOTNET
    Replies: 2
    Last Post: 03-28-2006, 01:10 PM