Get the App
SLTechnology News&Howtos  ›  Development  › 

How LINQ converts sequences or collections

Shulou Source: shulou.com Published: 2022-06-02 08:58:14 10月03日 Update

This article mainly explains "how to convert sequences or collections by LINQ". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to convert sequences or collections by LINQ".

A conversion sequence or collection.

We cannot convert sequences from T type to U type in C # or VB, even if T inherits from U class. Therefore, even converting List to List is difficult to achieve. For an explanation of why, see Bick Byer's post. But if you want to convert IEnumerable to IEnumerable, there is a simple and effective LINQ solution:

IEnumerable strEnumerable =... ; IEnumerable objEnumerable = strEnumerable.Cast ()

If we need to convert List to List, we also provide a LINQ solution, but it copies the list:

List strList =... ; List objList = new List (strList.Cast ())

Chris Cavanagh suggests another solution:

Var objList = strList.Cast (). ToList (); at this point, I believe you have a deeper understanding of "how LINQ converts sequences or collections", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Sequence content scheme type solution learning practical deeper effective interest practical practical post suggestion simple operation way method more friends website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS Linux Apple Docker