Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert List<Class> to String?

Tags:

string

c#

list

I've got an List and I want to convert it into string. Including all de strings and data that I've been added to my list.

This is my class

public class MyClass
{
    public Boolean success { get; set; }
    public String msg { get; set; }

}

Then I declare it in that way:

List<MyClass> list = addDataToList("Passwd", "UserID");

So, how can I convert that list to String?

Thanks for any help.

like image 272
HaOx Avatar asked Mar 11 '26 16:03

HaOx


1 Answers

If you want to concatenate all msg in the list then you can use string.Join as:

string str = string.Join(",", list.Select(r=> r.msg));
like image 120
Habib Avatar answered Mar 14 '26 04:03

Habib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!