.NET Fiddle

CSharp · Console

/Program.cs

using System;

public class Program
{
	public static void Main()
	{
		string input = "' | \" | < | > | &";
		
		input = input.Replace("&", "&amp;")
			.Replace("'", "&apos;")
			.Replace("\"", "&quot;")
			.Replace(">", "&gt;")
			.Replace("<", "&lt;");
		
		Console.WriteLine(input);
	}
}
;