我的代码库中有以下文件:
StandardUnits.Numbers.Double
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StandardUnits.Numbers
{
public class Double : Number<double>
{
public Double(double value) : base(value) { }
public static implicit operator Double(double value) { return new Double(value); }
public static implicit operator double(Double value) { return value._value; }
}
}
和
标准单元测试程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StandardUnits;
using StandardUnits.Numbers;
namespace StandardUnitsTest
{
class Program
{
static void Main(string[] args)
{
Equatable<string> str = "Hello! This is my number: ";
Number<float> n = 4;
Double o = 5.5;
Float p = n + o;
Console.WriteLine(str + p.ToString());
Console.Read();
}
}
}
出于某种原因,使用“Double”会产生以下错误:
Error 1 'Double' is an ambiguous reference between 'double' and 'StandardUnits.Numbers.Double' 16 13
但是“Float”不会产生这样的错误,它的制作方式与“Double”相同(但显然用“float”而不是“double”)。为什么编译器能够区分StandardUnits.Numbers.Float
and float
,但不能区分StandardUnits.Numbers.Double
and double
?为什么区分大小写不能阻止这种情况?
如果需要,我也可以提供 Number 和 Float 的代码片段。