Compare string created from copy in CSharp

Description

The following code shows how to compare string created from copy.

Example


//from   ww  w  . j a  v  a2 s  .  c o m
 using System;

 namespace StringManipulation
 {
    public class TesterStringCopyEqual
    {
       public void Run()
       {
           string s1 = "abcd";
           string s2 = "ABCD";

           // the string copy method
           string s5 = string.Copy(s2);
           Console.WriteLine(
               "s5 copied from s2: {0}", s5);

           // copy with the overloaded operator
           string s6 = s5;
           Console.WriteLine("s6 = s5: {0}", s6);

           // member method
           Console.WriteLine(
               "\nDoes s6.Equals(s5)?: {0}",
               s6.Equals(s5));

           // static method
           Console.WriteLine(
               "Does Equals(s6,s5)?: {0}",
               string.Equals(s6,s5));

           // overloaded operator
           Console.WriteLine(
               "Does s6==s5?: {0}", s6 == s5);
       }

       static void Main()
       {
          TesterStringCopyEqual t = new TesterStringCopyEqual();
          t.Run();
       }
    }
 }

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var