M
Marco Segurini
Hi,
The following code shows my problem:
using System;
using System.Collections.Generic;
using System.Text;
....
namespace ConsoleApplication1
{
static class MyOp
{
public static T Sub<T>(T item1, T item2)
where T : struct
{
return item1-item2; // this is line 118
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(MyOp.Sub(2,3));
}
}
}
Build result:
Program.cs(118,17): error CS0019: Operator '-' cannot be applied to
operands of type 'T' and 'T'
What have I to add to 'where' to tell to the generic function that T
implements operator- ?
Another question: the C# built-in types (byte,int,double,...) have
associated the same set of operation {+,-,*,/}: are these types derived
from common interface?
TIA.
Marco.
The following code shows my problem:
using System;
using System.Collections.Generic;
using System.Text;
....
namespace ConsoleApplication1
{
static class MyOp
{
public static T Sub<T>(T item1, T item2)
where T : struct
{
return item1-item2; // this is line 118
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(MyOp.Sub(2,3));
}
}
}
Build result:
Program.cs(118,17): error CS0019: Operator '-' cannot be applied to
operands of type 'T' and 'T'
What have I to add to 'where' to tell to the generic function that T
implements operator- ?
Another question: the C# built-in types (byte,int,double,...) have
associated the same set of operation {+,-,*,/}: are these types derived
from common interface?
TIA.
Marco.