繁体   English   中英

How can i fix Application' 是 'System.Windows.Application' 和 'System.Windows.Forms.Application' 之间的模棱两可的引用

[英]How can i fix Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'

我尝试使用“System.Application”“System.Windows.Application”代码:pastebin .com LK5F8HpA 我不能在这里说

如果在一个类中需要两个程序集,只需在特定类型的前面加上整个命名空间。

所以:

System.Windows.WhatEverIsNeededHere foo = new System.Windows.WhatEverIsNeededHere();

和:

System.Windows.Forms bar = new System.Windows.Forms();

解决此类歧义的方法是了解您正在使用什么以及为什么使用它。 然后使用正确的 using/importing 声明和/或使用完全限定名称,以便您的程序可以编译并且您没有歧义问题。

当您提出问题时,请提供有关您使用的框架以及您正在构建的版本和类型的应用程序的更多信息...表单? WPF? 核心版还是完整版? 等等

在 DotNet 命名空间中:System.Windows.Forms.Application、Assembly System.Windows.Forms.dll 而在核心中:命名空间:System.Windows、Assembly:PresentationFramework.dll

使用全限定名可以快速解决这个问题。

根据Msdn 链接,您可以使用命名空间别名和 '::' 运算符来解决您的问题。

快速解决

using forwinforms = System.Drawing;
using forwpf = System.Windows;

public class Converters
{
    public static forwpf::Point Convert(forwinforms::Point point) => new forwpf::Point(point.X, point.Y);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM