寻找错误的命名空间?

You*_*lty 1 .net c#

我有一些名称空间问题令我困惑,为什么会发生这种情况.

在下面的代码中,System.IO和System.Reflection试图引用abc.System,而不是使用我在顶部声明的System命名空间.这是为什么?

using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc.Data
{
public sealed class Access
{
    public static void Open(string dbPath)
    {
         // error here referencing abc.System in System.IO, and System.Reflection.

         string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);         }
}
Run Code Online (Sandbox Code Playgroud)

然后我在另一个文件中有另一个命名空间,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc.System
{
     public static class DateTimeExtensions
     {
    // Implemented from
    // http://stackoverflow.com/questions/38039/how-can-i-get-the-datetime-for-the-start-of-the-week
    public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
    {
        int diff = dt.DayOfWeek - startOfWeek;
        if (diff < 0)
        {
            diff += 7;
        }

        return dt.AddDays(-1 * diff).Date;
    }

    public static DateTime EndOfWeek(this DateTime dt, DayOfWeek startOfWeek)
    {
        int diff = dt.DayOfWeek - startOfWeek;
        if (diff < 0)
        {
            diff += 7;
        }

        return dt.AddDays(diff).Date;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

Tim*_*Tim 6

因为存在名称空间冲突,所以您需要使用该global关键字来明确您尝试访问的内容.

string appPath = global::System.IO.Path.GetDirectoryName(global::System.Reflection.Assembly.GetExecutingAssembly().Location); 
Run Code Online (Sandbox Code Playgroud)

或者,如果可以的话,更改您的命名空间,因为这会很快变得烦人!