【问题标题】:How can i fix Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'How can i fix Application' 是 'System.Windows.Application' 和 'System.Windows.Forms.Application' 之间的模糊引用
【发布时间】:2020-12-18 16:44:45
【问题描述】:

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

【问题讨论】:

  • 可能你同时有 using System.Windowsusing System.Windows,Forms 选择一个

标签: c# visual-studio roblox


【解决方案1】:

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

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

在 DotNet 命名空间中:System.Windows.Forms.Application、程序集 System.Windows.Forms.dll 在核心中:Namespace:System.Windows, Assembly:PresentationFramework.dll

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

【讨论】:

    【解决方案2】:

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

    快速修复

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

    【讨论】:

      【解决方案3】:

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

      所以:

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

      还有:

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

      【讨论】:

        猜你喜欢
        • 2022-12-27
        • 2023-01-31
        • 2022-11-20
        • 2022-12-02
        • 2022-12-28
        • 2022-11-20
        • 2022-11-09
        • 2022-12-01
        • 2022-12-27
        相关资源
        最近更新 更多