static void Main() { var namesA = new StringDisperser("gosho", "pesho", "tanio"); var namesB = new StringDisperser("gosho", "pesho", "tanio"); var cars = new StringDisperser("porshe", "volga", "ferrary"); var vegetables = new StringDisperser("carrot", "tommato", "cucumber"); Console.WriteLine("namesA == namesB: {0}", namesA == namesB); //True Console.WriteLine("namesA != cars: {0}", namesA != cars); //True Console.WriteLine("cars == vegetables: {0}", cars.Equals(vegetables)); //False var cloneNamesA = namesA.Clone(); Console.WriteLine("cloneNamesA == namesA: {0}", cloneNamesA.Equals(namesA)); var listOfStrings = new List <StringDisperser>() { namesA, namesB, cars, vegetables }; listOfStrings.Sort(); foreach (var output in listOfStrings) { Console.WriteLine(output); } }
static void Main() { StringDisperser stringDisperser = new StringDisperser("gosho", "pesho", "tanio"); StringDisperser stringDisperser2 = new StringDisperser("joro", "moro", "pepi"); Console.WriteLine(stringDisperser2 == stringDisperser); Console.WriteLine(stringDisperser2 != stringDisperser); Console.WriteLine(stringDisperser.Equals(stringDisperser2)); Console.WriteLine(stringDisperser); var stringDisperser3 = stringDisperser.Clone() as StringDisperser; stringDisperser3.Strings.Add("Mlechko"); Console.WriteLine(stringDisperser3); Console.WriteLine(stringDisperser); Console.WriteLine(); var stringDespersers = new List <StringDisperser> { stringDisperser, stringDisperser2, stringDisperser3 }; stringDespersers.Sort(); Console.WriteLine(string.Join("\n", stringDespersers)); Console.WriteLine(); foreach (var ch in stringDisperser) { Console.Write(ch + " "); } }
static void Main(string[] args) { StringDisperser stringDisperser = new StringDisperser("pesho"); StringDisperser stringDisperser2 = new StringDisperser("pesho"); // foreach foreach (var ch in stringDisperser) { Console.Write(ch + " "); } Console.WriteLine(); // check if equal Console.WriteLine(stringDisperser.Equals(stringDisperser2)); // true // check if equal with opearator != & == Console.WriteLine(stringDisperser != stringDisperser2); // true Console.WriteLine(stringDisperser == stringDisperser2); // false // clone and check if reference is the same var stringDisperser3 = (StringDisperser)stringDisperser.Clone(); Console.WriteLine(ReferenceEquals(stringDisperser, stringDisperser3)); // false // compare two StringDispersers var stringDisperser4 = new StringDisperser("pesho", "gosho", "tanio"); Console.WriteLine(stringDisperser.CompareTo(stringDisperser4)); }