Hello, is it possible to alter the following code under the generating pattern of the Factory Method, and if it is possible how:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace testNasledovanie { class Vector { public int[] arr; private const int size = 4; public virtual void Input() { Console.WriteLine("Initialzing"); arr = new int[size]; for (int i = 0; i < size; i++) { arr[i] = Int32.Parse(Console.ReadLine()); } } public virtual void Output() { Console.WriteLine("Your vector"); for (int i = 0; i < size; i++) { Console.WriteLine(arr[i] + " "); } } public virtual int Ymova() { int max = 0; for (int i = 0; i < size; i++) { if (arr[i] > max) max = arr[i]; } return max; } ~Vector() { Console.WriteLine("destructor vector is called."); Console.ReadKey(); } } class Maxtix : Vector { public int[,] array; private const int size = 4; public override void Input() { array = new int[size, size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { array[i, j] = Int32.Parse(Console.ReadLine()); } } } public override void Output() { Console.WriteLine("Your 2D array"); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Console.Write(array[i, j] + " "); } Console.WriteLine(); } } public override int Ymova() { int max = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (array[i, j] > max) max = array[i, j]; } } return max; } ~Maxtix() { Console.WriteLine("destructor matrix is called."); Console.ReadKey(); } } class Program { static void Main(string[] args) { int userSelect; Vector baseobj = new Vector(); do { Console.WriteLine("Enter '0' if you want to work with vector and 1 with matrix"); userSelect = Convert.ToInt32(Console.ReadLine()); if (userSelect == 0) { baseobj = new Vector(); baseobj.Input(); Console.WriteLine("max is " + baseobj.Ymova()); } else if (userSelect == 1) { baseobj = new Maxtix(); baseobj.Input(); Console.WriteLine("MAX IS " + baseobj.Ymova()); } else { return; } baseobj.Output(); } while (true); } } } This code allows you to create objects of classes of vector or matrix (there is a small menu). Thank you in advance!
Console.ReadKey();in the finalizer? o_O - VladD