You could just do this:
string s = "my original content";
s += File.ReadAllText(path);
But that is pretty inefficient:
string s = "my original content";
string fileData = File.ReadAllText(path);
StringBuilder sb = new StringBuilder(s.Length + fileData.Length);
sb.Append(s);
sb.Append(fileData);
s = sb.ToString();
Might be better, particularly if you are doing this a lot and can re-use the StringBuilder
"I am using open file dialog to select 5 files at runtime.
How to create five strings at runtime to store all text files in appropriate strings"
Try this:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
List<string> data = new List<string>();
foreach (string file in ofd.FileNames)
{
data.Add(File.ReadAllText(file));
}
}
Or this if you prefer Linq:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] data = ofd.FileNames.Select(f => File.ReadAllText(f)).ToArray();
}