Can I use ++ in adding 1 in build indices of scenes?

Visual studios has underlined red when I used my code like this. Is it wrong to use it like this?
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex++);
I am trying to add 1 in build index of scene to load the next scene. It works fine when I just used:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);

No you can’t because of several reasons. First of all the buildIndex is a read-only property. So you can not assign any value to it. Keep in mind that when you do x++ you actually do x = x + 1.

The second issue is that even if the property would be writeable, you would just reload the same scene. That’s because x++ is called the post-increment operator. That means the actual value that this expression evaluates to is just x and after (post) evaluation the variable is incremented. You would have to use the pre-increment operator that looks like ++x. This will first increment the variable and then evaluate the value. So you would get the incremented value.

Though as I said, buildIndex is readonly, so this doesn’t work. You could create a static property in one of your classes that does this:

public static int CurrentScene
{
    get => SceneManager.GetActiveScene().buildIndex;
    set => SceneManager.LoadScene(value);
}

With that property you could do

CurrentScene++;

and it would change to the next scene. You can also use

CurrentScene = 5;

To load the scene number 5. Though while this is possible, it’s not really recommended to use (abuse) a property for this. If this is your own project, you can of course do what you want. Though when you work in a team, make sure you properly document and discuss things like that with your team.

To make things a bit more safe the setter of the property might do some sanity checks on the passed index to avoid errors or to implement wrapping if desired.