有一个如下IAsyncEnumerable泛型类型的对象
IAsyncEnumerable<BlogComment> blogComments = await _blogCommentService.GetCommentsByPostId(Id);将IAsyncEnumerable类型转换为ICollection类型有如下方法方法1:强制转换
blogPost.BlogComments = (ICollection<BlogComment>)blogComments;方法2:使用List类型进行转换
blogPost.BlogComments = await blogComments.ToList();
本文介绍如何将IAsyncEnumerable<BlogComment>类型的数据转换为ICollection<BlogComment>类型,提供了两种方法:一是直接强制转换,二是通过ToListAsync()方法实现。
654

被折叠的 条评论
为什么被折叠?



