Share via

Resolve issue ") expected"

Scott Huang 3,511 Reputation points
2026-04-30T08:35:17.46+00:00

Hi,

I got the above error at the end of the last line below. Any reason?

User's image

User's image

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

  1. Jack Dang (WICLOUD CORPORATION) 17,585 Reputation points Microsoft External Staff Moderator
    2026-04-30T09:12:23.6+00:00

    Hi @Scott Huang ,

    Thanks for reaching out.

    That error is caused by a small syntax issue in the if statement. In C#, the condition inside an if must be a complete Boolean expression enclosed in parentheses.

    In your case, remove the comma after the IsUnicode(...) call and close the if condition properly:

    if (IsUnicode(str31.Substring(cnt3a, 1)))
    {
        // your code here
    }
    

    The comma makes the compiler think the expression is not finished, so it keeps looking for the rest of the statement and reports ) expected.

    Also, it is worth confirming that IsUnicode(...) returns a bool, since an if condition must evaluate to either true or false.

    If there is any chance that str31 could be empty, null, or that cnt3a could be outside the string length, you may also want to guard against that to avoid a runtime error:

    if (!string.IsNullOrEmpty(str31) && cnt3a >= 0 && cnt3a < str31.Length)
    {
        if (IsUnicode(str31.Substring(cnt3a, 1)))
        {
            // your code here
        }
    }
    

    So the main fix is simply to remove the comma and make sure the parentheses are balanced.

    Hope this helps! If my answer was also helpful to you, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.

    1 person found this answer helpful.

Answer accepted by question author

  1. Q&A Assist
    2026-04-30T08:35:29.8033333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error ") expected" is a syntax error indicating that a closing parenthesis is missing at the end of a list or expression.

    In the code shown, the call is:

    if (IsUnicode(str31.Substring(cnt3a, 1)),
    

    There is an extra comma after the method call and before the closing parenthesis of the if statement. The compiler therefore expects another argument or a closing parenthesis in a different place and reports the ") expected" error.

    Correct the line by removing the comma and ensuring parentheses are balanced, for example:

    if (IsUnicode(str31.Substring(cnt3a, 1)))
    {
        // ...
    }
    

    References:

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Julian Sharp 23,856 Reputation points
    2026-04-30T09:14:38.7233333+00:00

    If you are pasting in code from lab steps, you will find that Intellisense will often add or change the code automatically. You also can see excessive indentation

    You need to verify the code in your IDE matches the code snippet

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.