![]() |
|
|
#1 |
|
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. |
|
|
|
#2 |
|
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 |
|
|
|
#3 |
|
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. |
|
|
|
#4 |
|
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. |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|