Why does the compiler find this ambiguous?

In my base class, I have a common method (ideally this will be a property, but you cannot have common properties) and not a common property that has the same name:

protected static T CurrentUserId<T>()
{
    ...
}

protected static string CurrentUserId
{
    get
    {
        ...
    }
}

However, when I come to use any of them, intellisense reports an ambiguity between them. Undoubtedly base.CurrentUserId(without parethesese) provides enough hints to the compiler that I want to call a non-generic property?

Does anyone know why the compiler is struggling with this? Thanks in advance.

+2
source share
3 answers

Paul's comment on how “introducing generics into the mix seems to completely mask this more fundamental problem” seems to be true.

, , ( , , ). , , , , , .

( CurrentUserId), . :

# 2008 ,

" - - , ".

, :

  • ? , CurrentUserId.
  • ? , 0.
  • ? , .
  • ? , , , , .

, , , . , ( ) , , , . ( , ), .

, , ( ... ). , , , .

, .

+4

, . :

delegate T MyDelegate<T>();

new MyDelegate(myClass.CurrentUserId)

//are we talking about the method or the property?
+9

If you do not consider generics, for example:

public int Value { get;  set; }

public int Value()
{
    return 1;
}

You will also receive an error message: Type ... already contains a value definition

And I can think of one case when there is a clear conflict:

MyDelegate foo = new MyDelegate(Value);
+5
source

All Articles