Skip to content

Instantly share code, notes, and snippets.

@galek
Created January 17, 2017 00:23
Show Gist options
  • Save galek/b73471e3f938115af9e622b3aee23685 to your computer and use it in GitHub Desktop.
Save galek/b73471e3f938115af9e622b3aee23685 to your computer and use it in GitHub Desktop.
using System;
namespace Rextester
{
public class ArrayHelper
{
int[] _result;
public int[] result
{
get { return _result; }
set { this._result = value; }
}
public ArrayHelper(int _n)
{
result = new int[_n];
}
public ArrayHelper(int _n, int[]_r)
{
result = _r;
}
public static ArrayHelper operator +(ArrayHelper x, int[] y)
{
if (x.result.Length == y.Length)
{
var h = new ArrayHelper(x.result.Length);
int[] z = new int[x.result.Length];
for (int i = 0; i < x.result.Length; i++)
{
z[i] = x.result[i] + y[i];
}
return new ArrayHelper(x.result.Length, z);
}
return null;
}
public static ArrayHelper operator +(ArrayHelper x, ArrayHelper y)
{
if (x.result.Length == y.result.Length)
{
var h = new ArrayHelper(x.result.Length);
int[] z = new int[x.result.Length];
for (int i = 0; i < x.result.Length; i++)
{
z[i] = x.result[i] + y.result[i];
}
return new ArrayHelper(x.result.Length, z);
}
return null;
}
}
public class Program
{
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
const int n = 5;
int[] a = new int[n] { 1, 2, 3, 4, 5 };
int[] b = new int[n] { 5, 4, 3, 2, 1 };
var h1 = new ArrayHelper(n);
var h2 = new ArrayHelper(n);
h1.result = a;
h2.result = b;
// c = Add(a, b);
h1 = h1 + h2;
foreach (var item in h1.result)
{
Console.WriteLine(item.ToString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment