Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume that the following method is run (i.e., that it\'s part of a program that

ID: 3830591 • Letter: A

Question

Assume that the following method is run (i.e., that it's part of a program that compiles and runs this method). List out what output will be produced along with a quick (1-2 sentence) explanation about why each is printed. While you're of course welcome to use any technical jargon that you know it is expected that you'll use more casual writing; your should describe how the two variables interact with the operator or string. Compare method to produce the output in your own words public void RunExercise() {String mike = "Mike" string bob = "mike"; if (mike == bob) Console.WriteLine("TRUE at Point A"); else Console.WriteLine ("FALSE at Point A"); if (0 == String.Compare (mike, bob, true)) Console.WriteLine("TRUE at Point B"); else Console.WriteLine("FALSE at Point B"); Swtich (String.Compare (mike, "bob", true)) {case 0: Console.WriteLine("switch-case 0"); break; case - 1: Console.WriteLine("switch-case -1"); break; case 1: Console.WriteLine("switch-case 1"); break; default: Console.WriteLine("switch-default); break;}}

Explanation / Answer

String.Compare Method (String, String, Boolean) : Compares two specified String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order.

Less than zero : strA precedes strB in the sort order.
Zero : strA occurs in the same position as strB in the sort order.
Greater than zero : strA follows strB in the sort order.


OUTPUT :

[1]
FALSE at Point A
Reason : == compares the values of the strings ,which is case sensitive.

[2]
TRUE at Point B
Reason : Compares two specified String objects, ignoring or honoring their case

[3]
String.Compare(mike,"bob",true) ==> -1
--> switch-case -1
Reason : "bob" is smaller than "Mike"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote