I\'m trying to create a method to update an AssemblyInfo file with a new version string, using LINQ. I can successfully extract the string I need to update, but am not sure
You probably shouldn't try to use LINQ to modify the original query source, because it's awkward and error-prone, and not in the "style" of LINQ.
Instead, you can use LINQ as a filter to create a new array. All we need to do is rearrange your code a little:
private void UpdateVersion(string file, string version)
{
string[] asmInfo = File.ReadAllLines(file);
asmInfo = asmInfo.Select(x => x.Trim().StartsWith("[assembly: AssemblyVersion") ?
"[assembly: AssemblyVersion\"" + version + "\")]" : x).ToArray();
File.WriteAllLines(file, asmInfo);
}