It looks like you need to overload the + operator in order to provide the
necessary details to the runtime to be able to add the two types together.
HTH,
Greg
"Raju Shrestha" wrote:
[color=blue]
> I am trying to learn Generics with C# and tried following code:
>
> #region Using directives
>
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> #endregion
>
> namespace Generics
> {
> class Program
> {
> static void Main(string[] args)
> {
> Console.WriteLine("5+2 = " + Math.Add<int>(5,6));
> Console.WriteLine("1.2 + 3.3 = " + Math.Add<float>(1.2F,
> 3.3F));
> Console.ReadLine();
> }
> }
>
> class Math
> {
> public T Add<T>(T a,T b)
> {
> return (a + b);
> }
>
> }
> }
>
> It gives the error message "Operator '+' cannot be applied to operands
> of type 'T' and 'T'". Is this C# bug or something else. Appreciate for
> experts help.
> thanks!
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
>[/color]