Please consider the following:
public class MyObject { public bool B; public string Txt; } List<MyObject> list; //list of a bunch of MyObject's
With lambda expression, how can I produce a string consisting of comma separated values of Txt of those objects, where B is true?
Thank you.
Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball". In certain formalisations of concatenation theory, also called string theory, string concatenation is a primitive notion.
for .net 3.5:
string.Join(",", list.Where(o => o.B).Select(o => o.Txt).ToArray())
for .net 4.0:
string.Join(",", list.Where(o => o.B).Select(o => o.Txt))
string myString = string.Join(",", list.Where(x => x.B).Select(x=>x.Txt));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With