(); not appearing as shown in the video

Is there a setting that needs to be in place so that the brackets and semi-colon… ( );… appear automatically as shown in the video, for the Terminal.WriteLine (); statement. No matter how much I try, I have to type out the brackets and semi-colon myself. Not an issue to type out, but this auto-addition of (); could be quite a time saver.

I am new to this so not sure this is what you are looking for.

Look under preferences (maybe be called something different on PC) > Text Editor > Behavior and see if the Smart semicolon placement box is checked. If not, then add a check to the box and save your changes.

It doesn’t always work where you want it to so might have to remember to add it. You may need to save your script and restart Visual Studio. Hope this helps.

Thanks Morgaine. But couldn’t find mentioned check box. If any one else knows, please let me know.

I found this in MonoDevelop (Tools > Options > Text Editor > Behavior > Smart semicolon placement) but no equivalent in Visual Studio on Windows. I wonder if the autocomplete of (); is Mac-specific or if Ben has some add-on or …?

Visual Studio, by default, doesn’t provide this functionality.

If you were to type;

public bool Result

…and it automatically added the parenthesis after it, it would imply that this was a method, where-as it could be a member variable;

public class MyClass : MonoBehaviour
{
    public bool Result;
}

Visual Studio does provide auto-complete functionality however, so if you were to type;

public bool Result(

it would automatically add the closing bracket for you, thus;

public bool Result()

Visual Studio 2017 (Community edition or other), provides a wealth of customisation for the formatting of code, you can configure all of these options via the menu. Tools -> Options, and then expand the Text Editor section.

Specifically, look through the Code Style sub-section.

Knowing when to, and when not to, add parenthesis and braces is all part of your learning journey, I would recommend working through this manually and not relying on any tools or extensions that may offer to do this for you.

Thanks for that detail Rob. I could see the potential confusion if (); is not what is actually required.

You’re welcome Peter.

There is an extension called Resharper, it actually provides a lot of additional good things, but this will auto add parenthesis I believe. The downside, from memory, is that it adds them both, thus when you want to type in a method signature you have to delete the last one or fiddle with the mouse/cursor trying to get it in between!

Real World problems these :wink:

1 Like

Thank you all. If nothing else this was an interesting topic.

1 Like