【问题标题】:List Type Conversion Error列表类型转换错误
【发布时间】:2014-09-13 17:06:20
【问题描述】:

我有两个文件正在编辑以从一组列表中检查。我在其中一个文件的一行上收到以下错误:“无法将列表(字符串)隐式转换为列表(G.E.RE.DC)”我似乎无法弄清楚如何修复该错误。没有其他任何问题出现。

这是第一组代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace G.E.RE
{
    [Metadata("Claim", MetadataType.Object)]

    public class Claim
    {
        private List<string> diagCodes = new List<string>();
    }
    public List<DiagnosisCode> DC
    {
        get
        {
            if (testData != null)
                return testData.DC; //This is the line that shows the error

            return this.DC;
        }
        set
        {
            this.DC = value;
        }
    }
}

这是第二组代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using G.E.D.E.RE;

namespace G.E.RE
{
    public List<string> DC { get; set; }

    public class DC
    {
        public string Code { get; set; }
        public int ICDVersion { get; set; }
    }
}

【问题讨论】:

  • List&lt;string&gt; 是定义为List&lt;DiagnosisCode&gt; 的属性时,为什么要返回它?
  • 在第一个 sn-p 中,DC 应该是Claim 的属性吗?我想是的。但是在第二个 sn-p 中,我无法分辨 public List&lt;string&gt; DC { get; set; } 属于哪个类。是不是某个界面?
  • @ConradFrix,一旦你说我回去并意识到这是我的一个愚蠢的错误。我什至没有想过要定义的属性。猜猜你有时需要的只是让别人看看你的代码。谢谢。错误现在消失了。 :P
  • testData 声明在哪里?
  • @Jason9024 如果你修复了它,那么要么删除问题,要么发布答案,这样它就不会挂起。

标签: c# list type-conversion


【解决方案1】:

Conrad 指出我的属性被定义为 List,所以我将其他 List 更改为相同的类型。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using G.E.D.E.RE;

namespace G.E.RE
{
    public List<DiagnosisCode> DC { get; set; }

    public class DC
    {
        public string Code { get; set; }
        public int ICDVersion { get; set; }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    相关资源
    最近更新 更多