English 中文(简体)
以下方法或特性之间的呼吁含糊不清:
原标题:The call is ambiguous between the following methods or properties

附录二

public SomeClass(string a, Color? c = null, Font d = null)
        {
            // ...
        }

public SomeClass(string a, Font c = null, Color? d = null)
        {
            // ...
        }

我这样做:

SomeClass sc = new SomeClass("Lorem ipsum");

I ll get this: "Error 1 The call is ambiguous between the following methods or properties [...]"

在我看来,我指的是什么时候了,因为最终结果相同(至少就这一具体情况而言,对我来说,现在所有事情都如此),所以我可以选择什么来解决这一问题?

EDIT 1: @oltman: Simplified example.

I just want to be able to write

[...] new SomeClass("Lorem", Color.Green)

instead of

[...] new SomeClass("Lorem", null, Color.Green)
最佳回答

两名施工人员都持有相同数目的论点,但顺序不同。 由于你确定了两个构造参数的缺省值,汇编者不能区分两个超载体,而第二个论点没有提供。

I would advise you to remove the existing constructors and replace with the following:

public SomeClass(string a, Color? color, Font font)
{
    // constructor implementation
}

public SomeClass(string a) : this(a, null, null) {}
public SomeClass(string a, Color color) : this(a, color, null) {}
public SomeClass(string a, Font font) : this(a, null, font) {}
问题回答

强迫它工作的一种方式:

SomeClass sc = new SomeClass("Lorem ipsum", (Color?)null, (Font)null);

这是anti-pattern的一个完美例子,避免这种情况的最佳途径是@Phil Klein。

这里是另一条yn子,其穿过等级为:

SomeClass sc = new SomeClass("Lorem ipsum", null as Color, null as Font);

JetBrains Rider IDE issue

在我最近的案件中,JetBrains Rider在<代码>项目_名上添加了提及<代码>的项目_ 姓名/代码>的内容,其中产生了自我参照,并造成不时出现的错误:

<ItemGroup>
  <Reference Include="[project_name]">
    <HintPath>[path_to_dll_file]</HintPath>
  </Reference>
</ItemGroup>

The solution was to just revert this addition.

Can you create another constructor that takes just the string, and update the above constructors to make their second parameters mandatory?

如果主意是,你可以总是提供大体,然后是选择性地提供彩色或双体,从而构造这个物体,那么:

public SomeClass(string a)
        {
            // ...
        }

public SomeClass(string a, Color? c)
        {
            // ...
        }

public SomeClass(string a, Font f, Color? d = null)
        {
            // ...
        }

下面的意思是:“......在以下方法或特性之间,这种呼吁含糊不清......”

在我看来,我指的是什么时候了,因为最终结果相同。

电话is含混。 每个建筑师都是独一无二的,如果他们创建并返回一个榜样,就不成问题,因为每个建筑商可能有不同的逻辑。 汇编者仍然不知道你指的是什么。

I encountered this issue after installing the PnP.Framework, the replacement for SharePointPnPCoreOnline

我从项目档案中安装的SongPointPnPCoreOnline被搁置,试图清理,然后制造错误。

I hope this helps readers out there who will encounter the same issue as mine

Sometimes this error could be reported by an extension of your IDE such as OmniSharp,
even though your code compiles / is correct.
This was my case. I restarted it and the false-positive error went away.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签