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
Post a Comment