Search code examples
c#case-sensitivedisambiguation

C# - 'Double' is an ambiguous reference


I have the following files in my code base:

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; }
    }
}

and

StandardUnitsTest.Program

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();
        }
    }
}

For some reason, using "Double" produces the following error:

Error 1 'Double' is an ambiguous reference between 'double' and 'StandardUnits.Numbers.Double' 16 13

But no such error is produced for "Float", which is made in an identical fashion to "Double" (but with "float" instead of "double", obviously). Why is the compiler able to distinguish between StandardUnits.Numbers.Float and float, but not between StandardUnits.Numbers.Double and double? Why is case sensitivity not preventing this?

I can provide code snippets for Number and Float as well, if desired.


Solution

  • There is a conflict with System.Double.

    There is no System.Float (float is represented by System.Single instead), hence no conflict.