C # freely convert between ilist and ienumerable

Source: Internet
Author: User

One of the projects is used to connect the list <t>. However, after the Concat method is called, the connection result is converted to ienumerable <t>. How can I convert it back?

The ienumerable interface was suddenly found to have a conversion method: public static list <tsource> tolist <tsource> (this ienumerable <tsource> source!

Appendix, Example 1:

 

Code

Ilist <student> studentlist1 = new list <student> ();
Student S1 = new student ();
S1.id = "1 ";
S1.name = "James ";

Studentlist1.add (S1 );

Ilist <student> studentlist2 = new list <student> ();
Student S2 = new student ();
S2.id = "2 ";
S2.name = "Li Si ";

Studentlist2.add (S2 );

List <student> xxx = studentlist1.tolist ();
Xxx. addrange (studentlist2.tolist ());

Int C1 = xxx. count;

Ilist <student> YYY = studentlist1.concat (studentlist2). tolist <student> ();

Int C2 = yyy. count;

 

 

Online example address

NOTE: With a reminder from a colleague, I found a conversion method addrange and modified it to the sample code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.