Created
August 6, 2015 09:49
-
-
Save yanisurbis/f25fc825dd75634d2f49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication3 | |
{ | |
class My | |
{ | |
public static void Main() | |
{ | |
////creating | |
//MyPoint p = new MyPoint(); | |
//MyPoint k = new MyPoint(); | |
//MyPoint l = new MyPoint { X = 1, Y = 2, Z = 3 }; | |
//MyPoint n = new MyPoint { X = 1, Y = 2, Z = 3 }; | |
//MyPoint a = l; | |
////viewing | |
//Console.WriteLine(p.ToString()); | |
//Console.WriteLine(l.ToString()); | |
////equality | |
////Console.WriteLine(l.Equals(n)); | |
////Console.WriteLine(p.Equals(n)); | |
//Console.WriteLine("\n"); | |
//Console.WriteLine(Object.Equals(l, n)); | |
//Console.WriteLine(Object.Equals(l, a)); | |
////hash | |
//Console.WriteLine(l.GetHashCode()); | |
MyPoint a1 = new MyPoint(); | |
foreach (MyPoint x in a1) | |
Console.WriteLine(x.X); | |
Console.ReadLine(); | |
} | |
} | |
class MyPoint : IEnumerable | |
{ | |
int x; | |
int y; | |
int z; | |
MyPoint[] arr; | |
public int X | |
{ | |
get { return x; } | |
set { x = value; } | |
} | |
public int Y | |
{ | |
get { return y; } | |
set { y = value; } | |
} | |
public int Z | |
{ | |
get { return z; } | |
set { z = value; } | |
} | |
public MyPoint() | |
{ | |
arr = new MyPoint[4]; | |
arr[0] = new MyPoint { X = 1, Y = 2, Z = 3 }; | |
arr[1] = new MyPoint { X = 2, Y = 2, Z = 3 }; | |
arr[2] = new MyPoint { X = 3, Y = 2, Z = 3 }; | |
arr[3] = new MyPoint { X = 4, Y = 2, Z = 3 }; | |
Random r = new Random(); | |
x = r.Next(1, 101); | |
y = r.Next(1, 101); | |
z = r.Next(1, 101); | |
} | |
public IEnumerator GetEnumerator() | |
{ | |
return arr.GetEnumerator(); | |
} | |
public override string ToString() | |
{ | |
return String.Format("First field = {0}\nSecond field = {1}\nThird field = {2}\n", x, y, z); | |
} | |
public override bool Equals(object obj) | |
{ | |
MyPoint p = obj as MyPoint; | |
if (p != null) | |
{ | |
if (this.x == p.x && this.y == p.y && this.Z == p.Z) | |
return true; | |
} | |
return false; | |
} | |
public override int GetHashCode() | |
{ | |
return this.ToString().GetHashCode(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment