static void Main(string[] args) { IDictionary <CoordinatesStruct, string> d = IntPairToString.Factory.ConstructIntPairToStringDictionary(); { // with structs, 'new' doesn't allocate, it just initializes CoordinatesStruct c = new CoordinatesStruct(3, 4); d.Add(c, "Three by four"); } { CoordinatesStruct c = new CoordinatesStruct(6, 2); d.Add(c, "Six by two"); } //////////// Now let's read the data back //////////// { // This one should give null System.Console.Write("(2,2) gives "); CoordinatesStruct c = new CoordinatesStruct(2, 2); string s = null; d.TryGetValue(c, out s); System.Console.WriteLine((null == s) ? "null" : s); } { System.Console.Write("(3,4) gives "); CoordinatesStruct c = new CoordinatesStruct(3, 4); string s = null; d.TryGetValue(c, out s); System.Console.WriteLine((null == s) ? "null" : s); } { System.Console.Write("(6,2) gives "); CoordinatesStruct c = new CoordinatesStruct(6, 2); string s = null; d.TryGetValue(c, out s); System.Console.WriteLine((null == s) ? "null" : s); } }
public static CoordinatesStruct GetCoordinates(int p1, int p2) { CoordinatesStruct _co = new CoordinatesStruct(p1, p2); return(_co); }