为什么在不使用命名空间的类的命名空间和别名之间存在冲突? [英] Why is there a conflict between namespace and alias for a class that doesn't use the namespace?

查看:78
本文介绍了为什么在不使用命名空间的类的命名空间和别名之间存在冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某个类不使用引用的项目,如果该类具有与项目同名的别名,为什么仍然存在冲突?


示例:

使用AnotherProject = ProjectName.Properties.Resources; 

namespace ProjectName
{
public partial class App
{
public string ExplicitAccessWorksAsExpected => ProjectName.Properties.Resources.SomeResource;

//"ProjectName" project引用了"AnotherProject"。项目。此类不使用对"AnotherProject"的引用。项目。
//为什么在这样的情况下使用名为AnotherProject的别名不起作用?是否应该隐式使用using语句?
公共字符串AliasAccessNotWorking => AnotherProject.SomeResource;
}
}



  • ProjectName引用AnotherProject
  • App类没有使用来自AnotherProject的任何引用
  • 使用名为"AnotherProject"的别名将无效,因为它与名称空间"AnotherProject"冲突

这会产生错误CS0576








解决方案

为什么不将名称更改为其他名称并继续前进?

If a class doesn't use a referenced project, why is there still a conflict if the class has an alias which has the same name as the project?

Example:

using AnotherProject = ProjectName.Properties.Resources;

namespace ProjectName
{
    public partial class App
    {
        public string ExplicitAccessWorksAsExpected => ProjectName.Properties.Resources.SomeResource;

        // The "ProjectName" project has a reference to the "AnotherProject" project. This class doesn't use the reference to the "AnotherProject" project.
        // Why would using an alias called AnotherProject not work in a case like this? Shouldn't the using statements be implicitly used?
        public string AliasAccessNotWorking => AnotherProject.SomeResource;
    }
}

  • ProjectName references AnotherProject
  • App class doesn't use any reference from AnotherProject
  • Using an alias called "AnotherProject" won't work as it conflicts with the namespace "AnotherProject"

This produces error CS0576

解决方案

Why don't you just change the name to something else and move on?


这篇关于为什么在不使用命名空间的类的命名空间和别名之间存在冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆