您是否错过了演员

您是否错过了演员

本文介绍了无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Collections.Generic.List'。存在显式转换(您是否错过了演员?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程声明:

I have the following class declaration:

<blockquote class="FQ"><div class="FQA">Quote:</div> public class EventGroup
    {
        private readonly Guid id;
        private readonly string name;
        private readonly string description;
        private readonly Guid schoolId;

        public EventGroup(Guid id, string name, string description, Guid schoolID)
        {
            this.id = id;
            this.schoolId = schoolID;
            this.name = name;
            this.description = description;
        }
       public Guid SchoolID
        {
            get { return schoolId; }
        }
        public string Description
        {
            get { return description; }
        }
        public string Name
        {
            get { return name; }
        }
        public Guid ID
        {
            get { return id; }
        }

    }





当我声明以下工作时



When I declare the following its working

<blockquote class="FQ"><div class="FQA">Quote:</div>

List<EventGroup> lstGroup = new List<EventGroup>();
var eventt_grp= lstGroup.Select(r => new {r.ID,r.Name});





但如果不能正常工作我喜欢这样并得到错误:



But its not working if I do like this and getting the error:

Quote:

无法隐式转换类型'System.Collections.Generic.IEnumerable< anonymoustype#1>'到'System.Collections.Generic.List< tools.businessobjects.eventgroup>'。存在一个

显式转换(您是否错过了演员表?)

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<anonymoustype#1>' to 'System.Collections.Generic.List<tools.businessobjects.eventgroup>'. An
explicit conversion exists (are you missing a cast?)







<blockquote class="FQ"><div class="FQA">Quote:</div>

List<EventGroup> eventt_grp1 = lstGroup.Select(r => new {r.ID, r.Name });

推荐答案


IEnumerable eventt_grp = lstGroup.Select(r => new {r.ID, r.Name });


这篇关于无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Collections.Generic.List'。存在显式转换(您是否错过了演员?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:00