Пример #1
0
        private static void ElementAandElementBclassesTest()
        {
            Console.WriteLine("--- {0} ---", System.Reflection.MethodBase.GetCurrentMethod().Name);
            ElementA[] ela = new ElementA[10];
            ElementB[] elb = new ElementB[20];
            for (uint i = 0; i < ela.GetLength(0); i++)
            {
                ela[i]   = new ElementA();
                ela[i].X = (int)i;
                ela[i].Y = (int)i * 2;
                ela[i].Z = i.ToString() + "!!!";
            }
            for (uint i = 0; i < elb.Length; i++)
            {
                elb[i]   = new ElementB();
                elb[i].X = (int)i + 100;
                elb[i].Y = (int)i + 1000;
                elb[i].Z = (i + 10000).ToString() + "???";
            }

            foreach (var ea in ela)
            {
                Console.WriteLine("Ela.X = {0}\tEla.Y = {1}\tEla.Z = {2}", ea.X, ea.Y, ea.Z);
            }
            foreach (var eb in elb)
            {
                Console.WriteLine("Elb.X = {0}\tElb.Y = {1}\tElb.Z = {2}", eb.X, eb.Y, eb.Z);
            }
        }
Пример #2
0
        private static void CollectionsTests()
        {
            Console.WriteLine("--- {0} ---", System.Reflection.MethodBase.GetCurrentMethod().Name);
            ArrayList arlist = new ArrayList();

            arlist.Add(50);
            arlist.Add("sruu");
            arlist.Add("bleeee");
            ElementA ela = new ElementA();

            arlist.Add(ela);
            arlist.Add(ela);
            arlist.Add(new ElementB());
            arlist.Add(new Point(4, 3));
            arlist.Add(new Line(new Point(1, 2), new Point(3, 4)));
            arlist.Add(1.4f);
            arlist.Add(140.52m);
            arlist.Add(-100);
            arlist.Add(50);
            arlist.Add("sruu");
            arlist.Add("bleeee");
            arlist.Add(new ElementA());
            arlist.Add(new ElementB());
            arlist.Add(new Point(114, 344));
            Console.WriteLine(arlist[4]);

            foreach (object tmp in arlist)
            {
                if (tmp is Point)
                {
                    Console.WriteLine($"X:{((Point)tmp).X}\tY:{((Point)tmp).Y}");
                }
            }
            Console.WriteLine("arlist capacity: {0}\tarlist count: {1}", arlist.Capacity, arlist.Count);

            System.Collections.Generic.List <ElementA> list = new System.Collections.Generic.List <ElementA>();
            foreach (ElementA tmp in list)
            {
                Console.WriteLine(tmp.X);
            }

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("name", "Krzysztof");
            dict.Add("surname", "Krysiak");
            dict.Add("age", 10.ToString());

            Console.WriteLine($"Dictionary first key: {dict.First().Key} => last value: {dict.Last().Value}");
            foreach (KeyValuePair <string, string> tmp in dict)
            {
                Console.WriteLine($"{tmp.Key}: {tmp.Value.ToUpper()}");
            }

            SortedDictionary <string, string> sdict = new SortedDictionary <string, string>(dict);

            Console.WriteLine($"Sorted Dictionary first key: {sdict.First().Key} => last value: {sdict.Last().Value}");
            foreach (KeyValuePair <string, string> tmp in sdict)
            {
                Console.WriteLine($"{tmp.Key}: {tmp.Value}");
            }
        }