Q:

Write a C# Sharp program to perform and ordinal comparison of two strings that only differ in case

0

Write a C# Sharp program to perform and ordinal comparison of two strings that only differ in case. 

Expected Output :

Compare the numeric values of the corresponding Char objects in each string.     
str1 = 'JAVA', str2 = 'python'                                                   
String 'JAVA' is less than String 'python'.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
class Example31
{
    public static void Main() {
    String str1 = "JAVA";
    String str2 = "python";
    String str;
    int result;
    Console.WriteLine();
    Console.WriteLine("Compare the numeric values of the corresponding Char objects in each string.");
    Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2);
    result = String.CompareOrdinal(str1, str2);
    str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
    Console.Write("String '{0}' is ", str1);
    Console.Write("{0} ", str);
    Console.WriteLine("String '{0}'.", str2);
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now