LeetCode: Greatest Common Divisor of Strings C#
The first step in your method is to determine the longest common prefix. Here it would be sufficient to determine the length of the longest common prefix. Building the prefix string itself is not necessary at this point.

The next step is to decrease that length until it divides both string lengths. An explaining comment would be helpful here. We still don't need the prefix string itself, it suffices to decrease the previously determined prefix length.

Finally you determine if the prefix “divides” both strings. At this point we can build the actual prefix string. Again a short comment could be helpful. Instead of the inner loop I would compare substrings (unless that turns out to be too slow):

var prefix = str1.Substring(0, prefixLength);

// Verify that `str1` is a multiple of `prefix`:
for (int i = 1; i &lt; str1.Length / prefixLength; i++)
{
    if (prefix != str1.Substring(i * prefixLength, prefixLength))
    {
        return string.Empty;
    }
}

// Same for `str2` ...


Note that the loop can start with i = 1 because we already now that both strings start with prefix. Since the same logic is applied to both strings I would also consider to move it to a separate IsMultipleOf function.

Performance: Consider the following example:

str1 = "AAA......A"  //  999 characters
str2 = "AAA......AA" // 1000 characters


Your method builds a prefix string of 999 characters first, and then removes successively all but one character, because 1 is the only length that divides both string lengths.

As mentioned above, this can be improved by updating the prefix length only, but one can still do better:

It is not difficult to see that the length of X must be exactly the greatest common divisor of the lengths of str1 and str2 – and that can be determined efficiently with the Euclidean algorithm.

The implementation would then look like this:

private static int gcd(int a, int b)
{
    // Your favorite implementation of the Euclidean algorithm...
}

public static string GcdOfStrings(string str1, string str2)
{
    var prefixLength = gcd(str1.Length, str2.Length);
    var prefix = str1.Substring(0, prefixLength);

    // Is it a common prefix?
    if (prefix != str2.Substring(0, prefixLength)) {
        return "";
    }

    // Verify that `str1` is a multiple of `prefix` ...
    // Verify that `str2` is a multiple of `prefix` ...

    return prefix;
}