简体   繁体   English

如何解决与导入类型的冲突?

[英]How to fix conflicts with imported type?

I'm just creating a web application and I stuck with the problem. 我只是在创建一个Web应用程序,而我坚持了这个问题。 What is the correct way to inporting types? 导入类型的正确方法是什么? This is my classes into App_Data folder. 这是我进入App_Data文件夹的类。 Actually, all properties of my classes were changed like this: Build Action - Content (moved to Compile). 实际上,我的类的所有属性都进行了如下更改:生成操作-内容(移至编译)。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace sample.App_Code.HistoricalStock
{
    public class HistoricalStock
    {
        public DateTime Date { get; set; }
        public double Open { get; set; }
        public double High { get; set; }
        public double Low { get; set; }
        public double Close { get; set; }
        public double Volume { get; set; }
        public double AdjClose { get; set; }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using sample.App_Code.HistoricalStock;

namespace sample.App_Code.HistoricalStockDownload
{
    public class HistoricalStockDownloader
    {
        public static List<HistoricalStock> DownloadData(string ticker, int yearToStartFrom)
        {
            List<HistoricalStock> retval = new List<HistoricalStock>();

            // some code 

            return retval;


        }
    }
}

I don't really get your problem but it is not a good idea to have a type and namespace part with identical name. 我并没有真正解决您的问题,但是具有相同名称的类型和名称空间部分不是一个好主意。

  • your namespace: sample.App_Code.HistoricalStock 您的命名空间: sample.App_Code.HistoricalStock
  • your class: HistoricalStock 您的课程: HistoricalStock

Because when you try to use List<HistoricalStock> in the HistoricalStockDownloader class it may not even be compiled. 因为当您尝试在HistoricalStockDownloader类中使用List<HistoricalStock> ,它甚至可能没有被编译。

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

相关问题 类型____与导入的类型冲突 - The type ____ conflicts with imported type 类型与导入的名称空间冲突 - The type conflicts with imported namespace Xamarin程序集与导入的类型冲突 - Xamarin assembly conflicts with the imported type 类型X与导入的类型X冲突 - The type X conflicts with imported type X CS0436:类型与导入的类型冲突 - CS0436: Type conflicts with the imported type 如何处理&#39;File1.cs&#39;中的&#39;Foo&#39;类型与&#39;File2.dll&#39;中导入的类型&#39;Foo&#39;警告冲突 - How to deal with The type 'Foo' in 'File1.cs' conflicts with the imported type 'Foo' in 'File2.dll' warning 我收到错误“类型与导入的类型冲突 - I am getting an error "Type conflicts with the imported type Visual Studio 2008 奇怪的构建错误(类型与导入的类型冲突) - Visual Studio 2008 strange build error (type conflicts with imported type) 解决与导入类型的冲突 - Resolve conflicts with imported types 'path' 中的类型 'MyProgram' 与 'MyCode, Version=0.0.0.0, Culture=neutral, P 中导入的类型 'MyProgram' 冲突 - The type 'MyProgram' in 'path' conflicts with the imported type 'MyProgram' in 'MyCode, Version=0.0.0.0, Culture=neutral, P
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM