Method 1 (3 Arrays)
Create two arrays and then a third array to store the concatenated strings:
var codes = File.ReadAllLines( "Codes.txt" );
var countries = File.ReadAllLines( "Countries.txt" );
var lines = new List<string>( codes.Length );
for( int i = 0; i < codes.Length; i++ ) {
lines.Add( $"Code = {codes[ i ]}" + Environment.NewLine + $"Country = {countries[ i ]}" );
}
File.WriteAllLines( "Result.txt", lines);
Method 2 (2 Arrays so less memory)
If you do not want the third array due to memory consumption, then you can use one of the array you already have and store the concatenated strings in them:
var codes = File.ReadAllLines( "Codes.txt" );
var countries = File.ReadAllLines( "Countries.txt" );
for( int i = 0; i < codes.Length; i++ ) {
codes[i] = $"Code = {codes[ i ]}" + Environment.NewLine + $"Country = {countries[ i ]}";
}
File.WriteAllLines( "Result.txt", codes );
This is the best option because it is the best of both worlds: less memory and only 3 IO operations (2 reads, 1 write).
Method 3 (1 Array so lesser memory)
This technique will read all countries into memory and then read one line from the codes file into memory, write it to the destination file, and then read another line from the codes file. So at any given time, there is only one code in memory. This is achieved using File.ReadLines.
var countries = File.ReadAllLines( "Countries.txt" );
int i = 0;
File.WriteAllLines( "Result2.txt", File.ReadLines( "Codes.txt" )
.Select( x => $"Code = {x}" + Environment.NewLine + $"Country = {countries[ i++ ]}" ) );