c# - ForEach to Trim string values in string array -



c# - ForEach to Trim string values in string array -

i wondered why foreach doesn't work , leaves values trailing whitespace.

string days = "monday, tuesday, wednesday, thursday, friday"; string[] m_days = days.split(','); m_days.tolist().foreach(d => { d = d.trim(); } );

i know there other ways of doing don't need , reply there.

because not reassigning trimmed strings.

var list = m_days.split(',').select(s => s.trim()).tolist();

why foreach doesn't work or if using foreach incorrectly?

foreach not linq, it's method of list<t>. doing this:

foreach(string day in m_days) { day.trim(); // throwing away new string }

c# asp.net foreach

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -