Ejemplo n.º 1
0
        public StringDisperser Clone()
        {
            List <char> result = new List <char>();

            this.characters.ToList().ForEach(result.Add);
            StringDisperser cloning = new StringDisperser(result);

            return(cloning);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            StringDisperser stringDisperser = new StringDisperser("gosho", "pesho", "tanio");

            StringDisperser secondStringDisperser = new StringDisperser("gosho", "pesho", "tanio");

            StringDisperser clonedStringDisparser = (StringDisperser)secondStringDisperser.Clone();

            Console.WriteLine(stringDisperser == secondStringDisperser);
            Console.WriteLine(secondStringDisperser.Equals(clonedStringDisparser));

            Console.WriteLine(stringDisperser.CompareTo(secondStringDisperser));

            foreach (var ch in stringDisperser)
            {
                Console.Write(ch + " ");
            }
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            StringDisperser stringDisperser = new StringDisperser("gosho", "pesho", "tanio");

            Console.WriteLine(stringDisperser);
            foreach (var ch in stringDisperser)
            {
                Console.Write(ch + " ");
            }
            Console.WriteLine();

            StringDisperser otherDisperser = new StringDisperser("alabala", "portokala");

            Console.WriteLine(otherDisperser);
            Console.WriteLine(otherDisperser == stringDisperser);
            Console.WriteLine(otherDisperser.CompareTo(stringDisperser));

            StringDisperser clonedDisperser = stringDisperser.Clone();

            Console.WriteLine(clonedDisperser);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            StringDisperser stringDisperser  = new StringDisperser("gosho", "pesho", "tanio");
            StringDisperser stringDisperser1 = new StringDisperser("gosho", "pesho", "tanio");

            // test == and Equal
            if (stringDisperser == stringDisperser1)
            {
                Console.WriteLine(stringDisperser);
            }

            Console.WriteLine();

            // test clone
            StringDisperser stringDisperser2 = (StringDisperser)stringDisperser1.Clone();

            stringDisperser1.Add("tralala");
            Console.WriteLine(stringDisperser1);
            Console.WriteLine(stringDisperser2);

            Console.WriteLine();

            // test compareTo by sorting array with StringDisperser
            StringDisperser stringDisperser3 = new StringDisperser("ala", "bala");

            StringDisperser[] stringDispersers = new StringDisperser[] { stringDisperser2, stringDisperser1, stringDisperser, stringDisperser3 };
            Array.Sort(stringDispersers);
            for (int i = 0; i < stringDispersers.Length; i++)
            {
                Console.WriteLine(stringDispersers[i]);
            }

            Console.WriteLine();

            // test IEnumerable
            foreach (var item in stringDispersers)
            {
                Console.WriteLine(item);
            }
        }
Ejemplo n.º 5
0
 public int CompareTo(StringDisperser other)
 {
     return(string.Compare(this.ToString(), other.ToString(), StringComparison.InvariantCulture));
 }
Ejemplo n.º 6
0
        public override bool Equals(object obj)
        {
            StringDisperser otherDisperser = obj as StringDisperser;

            return(otherDisperser != null && Equals(this.characters, otherDisperser.characters));
        }