コード例 #1
0
    public static void Swap <T>(List <GenericBox <T> > list, int firstPosition, int secondPosition)
    {
        GenericBox <T> oldFirstPositionValue = list[firstPosition];

        list[firstPosition]  = list[secondPosition];
        list[secondPosition] = oldFirstPositionValue;
    }
コード例 #2
0
    public static void Main()
    {
        List <GenericBox <string> > boxes = new List <GenericBox <string> >();

        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            GenericBox <string> box = new GenericBox <string>(Console.ReadLine());
            boxes.Add(box);
        }

        string comparator    = Console.ReadLine();
        int    biggerCounter = 0;

        for (int i = 0; i < n; i++)
        {
            if (boxes[i].Value.CompareTo(comparator) > 0)
            {
                biggerCounter++;
            }
        }

        Console.WriteLine(biggerCounter);
    }
コード例 #3
0
        public void ShouldSerializeNullNullable()
        {
            var box = new GenericBox <int?> {
                Element = null
            };
            var copy = SerializerClone(box);

            Assert.AreEqual(box.Element, copy.Element);
        }
コード例 #4
0
        public void ShouldSerializeBoxWithGuid()
        {
            var box = new GenericBox <Guid>();

            box.Element = Guid.NewGuid();
            var copy = SerializerClone(box);

            Assert.AreEqual(box.Element, copy.Element);
        }
コード例 #5
0
        public void ShouldSerializeBoxWithLong()
        {
            var box = new GenericBox <long> {
                Element = 1234
            };
            var copy = SerializerClone(box);

            Assert.AreEqual(box.Element, copy.Element);
        }
コード例 #6
0
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            GenericBox <int> box = new GenericBox <int>(int.Parse(Console.ReadLine()));
            Console.WriteLine(box.ToString());
        }
    }
コード例 #7
0
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            string input = Console.ReadLine();
            GenericBox <string> generic = new GenericBox <string>(input);
            Console.WriteLine(generic);
        }
    }
コード例 #8
0
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            int number = int.Parse(Console.ReadLine());
            GenericBox <int> genericInt = new GenericBox <int>(number);
            Console.WriteLine(genericInt);
        }
    }
コード例 #9
0
        public void ShouldSerializeStructInClass()
        {
            var str = new SimpleStruct {
                A = 1, B = "allman"
            };
            var box = new GenericBox <SimpleStruct> {
                Element = str
            };
            var copy = SerializerClone(box);

            Assert.AreEqual(str, copy.Element);
        }
コード例 #10
0
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            var    boxOfStrings = new GenericBox <string>();
            string input        = Console.ReadLine();

            boxOfStrings.Add(input);

            Console.WriteLine(boxOfStrings);
        }
    }
コード例 #11
0
    public static void Main()
    {
        var boxOfStrings = new GenericBox <double>();

        double n = double.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            double input = double.Parse(Console.ReadLine());

            boxOfStrings.Add(input);
        }

        double compareTo = double.Parse(Console.ReadLine());

        Console.WriteLine(boxOfStrings.CompareItems(compareTo));
    }
コード例 #12
0
    public static void Main()
    {
        var boxOfStrings = new GenericBox <string>();

        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            string input = Console.ReadLine();

            boxOfStrings.Add(input);
        }

        string compareTo = Console.ReadLine();

        Console.WriteLine(boxOfStrings.CompareItems(compareTo));
    }
コード例 #13
0
        public void ShouldFindPathToPointerContainingObject()
        {
            Exception exception = null;
            var       toClone   = new GenericBox <AnotherContainingType>();

            toClone.Element = new AnotherContainingType();
            try
            {
                SerializerClone(toClone);
                Assert.Fail("Exception was not thrown.");
            }
            catch (Exception e)
            {
                exception = e;
            }
            Assert.IsTrue(exception.Message.Contains(toClone.GetType().Name));
            Assert.IsTrue(exception.Message.Contains(toClone.Element.GetType().Name));
            Assert.IsTrue(exception.Message.Contains(toClone.Element.WithIntPtr.GetType().Name));
        }
コード例 #14
0
    public static void Main()
    {
        var boxOfStrings = new GenericBox <int>();

        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            int input = int.Parse(Console.ReadLine());

            boxOfStrings.Add(input);
        }

        int[] indexes     = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int   firstIndex  = indexes[0];
        int   secondIndex = indexes[1];

        boxOfStrings.Swap(firstIndex, secondIndex);

        Console.WriteLine(boxOfStrings);
    }
コード例 #15
0
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        List <GenericBox <string> > genericList = new List <GenericBox <string> >();

        for (int i = 0; i < n; i++)
        {
            string input = Console.ReadLine();
            GenericBox <string> genericString = new GenericBox <string>(input);
            genericList.Add(genericString);
        }
        int[] swapPositionsInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int   startIndex        = swapPositionsInfo[0];
        int   lastIndex         = swapPositionsInfo[1];

        GenericBox <string> .Swap(genericList, startIndex, lastIndex);

        foreach (var generic in genericList)
        {
            Console.WriteLine(generic);
        }
    }
コード例 #16
0
    public static void Main()
    {
        Dictionary <int, GenericBox <string> > boxes = new Dictionary <int, GenericBox <string> >();

        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            GenericBox <string> box = new GenericBox <string>(Console.ReadLine());
            boxes[i] = box;
        }

        List <int>          swap     = Console.ReadLine().Split().Select(int.Parse).ToList();
        GenericBox <string> swapThis = null;

        swapThis       = boxes[swap[0]];
        boxes[swap[0]] = boxes[swap[1]];
        boxes[swap[1]] = swapThis;

        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(boxes[i].ToString());
        }
    }
コード例 #17
0
    public static void Main()
    {
        List <GenericBox <int> > boxes = new List <GenericBox <int> >();

        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            GenericBox <int> box = new GenericBox <int>(int.Parse(Console.ReadLine()));
            boxes.Add(box);
        }

        List <int>       swap     = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
        GenericBox <int> swapThis = null;

        swapThis       = boxes[swap[0]];
        boxes[swap[0]] = boxes[swap[1]];
        boxes[swap[1]] = swapThis;

        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(boxes[i].ToString());
        }
    }