1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
   | using System;
using System.Collections.Generic;
 
static class Program
{
    static class Vector2D
    {
        static public Dictionary<string, object> Add(params object[] arguments)
        {
            Dictionary<string, object> sum = new Dictionary<string, object>();
            sum["x"] = ((Dictionary<string, object>)arguments[0])["x"];
            sum["y"] = ((Dictionary<string, object>)arguments[0])["y"];
            for (int i = 1; i < arguments.Length; i++)
            {
                sum["x"] =  (double)sum["x"] + (double)((Dictionary<string, object>)arguments[i])["x"];
                sum["y"] =  (double)sum["y"] + (double)((Dictionary<string, object>)arguments[i])["y"];
            }
            return sum;
        }
    }
 
    static void Main(string[] args)
    {
        Dictionary<string, object> v1 = new Dictionary<string, object>();
        v1["x"] = 1.5;
        v1["y"] = 3.0;
 
        Dictionary<string, object> v2 = new Dictionary<string, object>();
        v2["x"] = 2.5;
        v2["y"] = -2.3;
 
        Dictionary<string, object> v3 = Vector2D.Add(v1, v2);
        Console.WriteLine(" x: {0} , y : {1}", v3["x"], v3["y"]);
    }
} | 
Partager