Which three code blocks should you use to develop the solution?

Drag Drop
You are creating a method. by using C#. The method will accept three strings as parameters. The parameters are named string1, string2, and string3. The parameter values range from 5,000 to 15,000 characters.
The method. will have the following signature.

You need to ensure that StringCompare only returns true if string1 concatenated to string2 is equal to string3. The comparison must be case-insensitive. The solution must ensure that StringCompare executes as quickly as possible.
Which three code blocks should you use to develop the solution? To answer, move the appropriate code blocks from the list of code blocks to the answer area and arrange them in the correct order.
NOTE: Each correct selection is worth one point.
Select and Place:

microsoft-exams

11 thoughts on “Which three code blocks should you use to develop the solution?

  1. 1,2,5 and 3,2,5 both work. I’ve tested them in VS.
    3,2,5 is a little bit faster and 1,2,5 uses less memory.

    1
    1
  2. This is how I think the method should be written in order to match the requirements:

    public bool StringCompare(string string1, string string2, string string3)
    {
    string concatStrings = string1 + string2;

    bool result = concatStrings.ToString().Equals(string3, StringComparison.CurrentCultureIgnoreCase);

    return result;
    }

  3. Doc (https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder?view=netframework-4.8) says:
    Consider using the StringBuilder class under these conditions:
    *When you expect your app to make an unknown number of changes to a string at design time (for example, when you are using a loop to concatenate a random number of strings that contain user input).
    *When you expect your app to make a significant number of changes to a string.

    So, when the number of changes is known and does not significant, we should use string concatination, not StringBuilder.
    I wrote several tests in Visual Studio to check that fact and correct answers should be 1,2,5

    1. I agree, answers should be 3, 2, 5.

      The suggested, original answer calls the ToString() method on a variable which is already a string, which should not be the solution.
      All code blocks which determine the result of the method do call the ToString() method, so the solution must be with a StringBuilder and not a String.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.