On Thu, Oct 15, 2009 at 1:20 PM, Awadhendra Tiwari <
[email protected]> wrote:

>
> if it is not so simple then how can i perform numeric calculation on
> generic data type.........
>

It depends on your .NET version....

.NET 2.0
1. <http://www.codeproject.com/KB/cs/genericnumerics.aspx> - This
article uses code from Eric Gunnerson's blog and demonstrates using an
abstract class that needs to be specialized for each type
specification.

.NET 3.x:
1. <http://rogeralsing.com/2008/02/27/linq-expressions-calculating-
with-generics<http://rogeralsing.com/2008/02/27/linq-expressions-calculating-with-generics>>
- This article shows how to use Linq Expression trees
to accomplish this.

2. <http://www.yoda.arachsys.com/csharp/genericoperators.html> - This
article on Jon Skeet's site uses the MiscUtil library developed by
Marc Gravell to accomplish this. Its USP is that efficiency has not
been sacrificed. Internally, the library also uses Expression tree
lambdas.

.NET 4.0:
1. <http://geekswithblogs.net/sdorman/archive/2008/11/16/c-4.0-dynamic-
programming.aspx> - C# 4.0 introduces the "dynamic" keyword which
allows method calls to be resolved at runtime, rather than blocked by
the compiler. This provides another (cleaner) solution to the problem.

Reply via email to