Exemplo n.º 1
0
        public static void UserDeserialization(out UserContainer <UserArrayList <Rhombus> > obj)
        {
            XmlSerializer xmlSer = new XmlSerializer(typeof(UserContainer <UserArrayList <Rhombus> >));

            using (Stream stream = new FileStream("example.xml", FileMode.Open)) {
                obj = (UserContainer <UserArrayList <Rhombus> >)xmlSer.Deserialize(stream);
            }
        }
Exemplo n.º 2
0
        public static void UserSerialization(UserContainer <UserArrayList <Rhombus> > obj)
        {
            XmlSerializer xmlSer = new XmlSerializer(obj.GetType());

            using (Stream stream = new FileStream("example.xml", FileMode.Create, FileAccess.Write, FileShare.None)) {
                xmlSer.Serialize(stream, obj);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            #region input
            uint amountOfCollections;
            CheckInput(out amountOfCollections, "Enter amount of collections");

            // creating & filling UserContainer with empty UserArrayLists
            var array = new UserContainer <UserArrayList <Rhombus> >();
            for (int i = 0; i < amountOfCollections; i++)
            {
                array.Add(new UserArrayList <Rhombus> ());
            }

            // filling all collections with random data & sizes
            Random rand = new Random();
            foreach (var coll in array)
            {
                int size = rand.Next(1, 5) + 1;
                for (int j = 0; j < size; j++)
                {
                    coll.AddData(new Rhombus((float)(rand.NextDouble() * 5 + 2), (float)(rand.NextDouble() * 5 + 2)));
                }
            }

            //sorting all collections by area
            for (int i = 0; i < amountOfCollections; i++)
            {
                array.data[i].Sort();
            }
            #endregion
            #region linq
            // getting count of collections sums bigger than defined value
            uint minArea;
            CheckInput(out minArea, "Enter minimum area to select by");
            int res1 = (from coll in array where coll.Sum(el => el.Area) > minArea select coll).Count();
            Console.WriteLine($"Amount of collections with sum bigger than {minArea} equals {res1}\n");

            // getting least sum of elements from collection of collections
            var res2 = (from coll in array orderby coll.Sum(el => el.Area) select coll).First();
            Console.WriteLine("Least collections by sum :");
            res2.Info();

            // getting biggest sum of elements from collection of collections
            var res3 = (from coll in array orderby coll.Sum(el => el.Area) descending select coll).First();
            Console.WriteLine("Biggest collection by sum :");
            res3.Info();
            #endregion
            #region serialization
            // Serialization
            UserSerialization(array);

            // Deserialization
            UserContainer <UserArrayList <Rhombus> > array2;
            UserDeserialization(out array2);
            #endregion
            #region output
            // printing info about each collection
            int index = 0;
            foreach (var coll in array2)
            {
                Console.WriteLine($"UserArrayList[{index++}] with sum : {coll.Sum(el => el.Area)}");
                foreach (var el in coll)
                {
                    Console.WriteLine(el);
                }
            }
            #endregion
        }