I have this:
var lineArray = line.Split(\';\');
lineArray.ToList().ForEach(x =>
{
if (x == \"(null)\")
x = \"NULL\";
else
x = string.
var lineArray = line.Split(';')
.Select(x=>x == "(null)"
? "NULL"
: string.Format("'{0}'", x))
.ToArray();
you are trying to use List
with lambda expression (T is string here)
if lambda expression is replaced with named method it turns out that only method argument is modified, but changes are not reflected on calling side, because x
is not ref
argument
private void Replace(string x)
{
if (x == "(null)")
x = "NULL";
else
x = string.Format("'{0}'", x);
}
var list = lineArray.ToList();
list.ForEach(Replace);
// check list here and make sure that there are no changes
ForEach could work if T is a reference type and action modifies some properties but not the reference itself