Romonov Romonov - 8 months ago 56
C# Question

Replace a specific item in IEnumerable<string>

I am new to C# and dealing with IEnumerable. I want to replace a specific item in IEnumerable. E.g.

IEnumerable<string> m_oEnum = new string[] {"abc","def","ghi", "abcdef"};

I only want to replace the string "abc" with "abc-test", but not change "abcdef".

m_oEnum  = m_oEnum.Select(s => s == "abc" ? "abc-test" : s).ToArray();