Build Clone able objects-
using System;
class Program
{
static void Main()
{
string[] arr = { "Amit", "Nitin", "Ankit", "Sunny", "Rahul" };
string[] arrCloned = arr.Clone() as string[];
Console.WriteLine(string.Join(",", arr));
Console.WriteLine(string.Join(",", arrCloned));
Console.ReadLine();
}
}
Build Comparable objects-
using System;
namespace StringComapreSample
{
class Program
{
static void Main(string[] args)
{
string author1 = "Mahesh Chand";
string author2 = "Praveen Kumar";
string author3 = "Mahesh Chand";
// Compare strings using String.Equals
if (String.Equals(author1, author2))
Console.WriteLine($"{author1} and {author2} have same value.");
else
Console.WriteLine($"{author1} and {author2} are different.");
if (String.Equals(author1, author3))
Console.WriteLine($"{author1} and {author3} have same value.");
else
Console.WriteLine($"{author1} and {author3} are different.");
// Use CompareTo method
if (author1.CompareTo(author2) == 0)
Console.WriteLine($"Both strings have same value.");
else if (author1.CompareTo(author2) < 0)
Console.WriteLine($"{author1} precedes {author2}.");
else if (author1.CompareTo(author2) > 0)
Console.WriteLine($"{author1} follows {author2}.");
Console.ReadLine();
}
}
}