.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Globalization;
					
public class Program
{
	public static void Main()
	{
		string aString = "040204220442040004200404020602260246";

 		if ((aString.Length % 2) != 0)
    	{
        	// Handle invalid input
    	}
		
		var bytes = new byte[aString.Length / 2];

		int index = 0;
		for (int i = 0; i < aString.Length; i += 2)
		{
			string digits = aString.Substring(i, 2);
    		byte aByte = (byte)int.Parse(digits, NumberStyles.HexNumber);
		
			bytes[index++] = aByte;
		}
		
		foreach (byte aByte in bytes)
		{
			Console.WriteLine(aByte);
		}
	}
}
;