I (try) to find out about generics, and I thought I understood them. I have the following code for a general class:
and in Main() I can create objects in order:
Point<int> pt = new Point<int>(); Point<double> pt2 = new Point<double>(); Point<string> pt3 = new Point<string>(); pt.X = 10; pt2.X = 10; pt3.X = "10";
Now I can run the Subtract method on two int s, double or even string s, but I canβt work on mixed, and I thought I could because of .ToDouble .
If I try to run Console.WriteLine(pt.Subtract(pt2)); I get the following errors:
Error 1 The best overloaded method match for Date.Point<int>.Subtract(Date.Point<int>)' has some invalid arguments Error 2 Argument 1: cannot convert from 'Date.Point<double>' to 'Date.Point<int>'
The code itself is not so important, because I'm just trying to understand / learn generalizations, so I just would like to understand what is wrong here and why this will not work ... The actual method is not so important / will not be used.
source share