1

I have a class like this

public class test{
        public string a { get; set; }
        public string b { get; set; }
}

and a list of objects

List<test> list= new List<test>();
list.Add(new test() {a = "1a", b = "1b" });
list.Add(new test() {a = "2a", b = "2b" });
...

i want concatenate the elements and have a string like

"1a 1b + 2a 2b" ... etc

Can i use Linq to do this?

2 Answers 2

1

This can be done in Linq by mapping to a string as follows.

string Result =
    String.Join(" + ", 
        list.Select(iObj => String.Format("{0} {1}", iObj.a, iObj.b)));
Sign up to request clarification or add additional context in comments.

Comments

0
String.Join(" + ", list.Select(x => /*What you want*/)); 

will do the trick!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.