TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 15-12-2007, 06:15 AM   #1
My interest
Guest
 
Posts: n/a
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.
  Reply With Quote
Old 15-12-2007, 06:16 AM   #2
Marc Gravell
Guest
 
Posts: n/a
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
  Reply With Quote
Old 15-12-2007, 06:17 AM   #3
Peter Duniho
Guest
 
Posts: n/a
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.
  Reply With Quote
Old 15-12-2007, 06:17 AM   #4
My interest
Guest
 
Posts: n/a
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 With Quote
Reply

Thread Tools
Display Modes


Google
 


All times are GMT +5.5. The time now is 05:27 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional