.NET Fiddle

CSharp · Console

/Program.cs

using System;

namespace ConsoleApplication1
{
	public class Program
	{
		public static void Main()
		{
			var matrixInt = new GenericMatrix<int>(5, 5, GetInt);
			var matrixDouble = new GenericMatrix<double>(5, 5, GetDouble);
		}

		public static int GetInt(int x, int y)
		{
			var valueAsString = Console.ReadLine();
			return Convert.ToInt32(valueAsString);
		}

		public static double GetDouble(int x, int y)
		{
			var valueAsString = Console.ReadLine();
			return Convert.ToDouble(valueAsString);
		}
	}

	public class GenericMatrix<Number>
	{
		private readonly Number[,] _matrix;

		public delegate Number GetNumber(int x, int y);

		public GenericMatrix(int cols, int rows, GetNumber getNumberFunc)
		{
			_matrix = new Number[cols, rows];

			for (var x = 0; x < cols; x++)
				for (var y = 0; y < rows; y++)
					_matrix[x, y] = getNumberFunc(x, y);
		}
	}
}
;