❔ LINQ
Does linq have its own replace method? If so, does it make a new string or modify? Also is there a way to replace a string without making new string?
unsafe territory and start swapping bytes around... no, you can't change a string without making a new string/close "dog""cat"["dog", "is", "dog"]["cat", "is", "cat"]Z
B
CZ
B
Y var strings = new List<string>() { "A", "B", "C" };
var updated = strings.Select(x =>
{
if (x == "A")
{
return "Z";
}
return x;
});
foreach (var s in updated)
{
Console.WriteLine(s);
}var strings = new List<string>() { "A", "B", "C" };
var updated = strings.Select(x =>
{
return x switch
{
"A" => "Z",
"C" => "Y",
_ => x
};
});
foreach (var s in updated)
{
Console.WriteLine(s);
}