Zircon The latest code HelpDialog.cs compilation resulted Compiler Error CS0131

test39857

LOMCN Rookie
Mar 26, 2024
11
0
2
The latest code HelpDialog.cs compilation resulted Compiler Error CS0131. HelpDialog.cs code as below:

public void OnSelectedChanged(HelpContainer oValue, HelpContainer nValue)
{
oValue?.Visible = false;

SelectedChanged?.Invoke(this, EventArgs.Empty);

nValue?.Update();

nValue?.Visible = true;
}

Compiler Error CS0131:The left-hand side of an assignment must be a variable, property or indexer

I checked the grammar and there are no errors, but I don't know why this error keeps occurring.

However, the equivalent code shown below compiles successfully. Could someone please explain this discrepancy?

public void OnSelectedChanged(HelpContainer oValue, HelpContainer nValue)
{
//oValue?.Visible = false;
if (oValue != null)
{
oValue.Visible = false;

}

SelectedChanged?.Invoke(this, EventArgs.Empty);

nValue?.Update();

//nValue?.Visible = true;
if (nValue != null)
{
nValue.Visible = true;

}

}
 

Shyfx

LOMCN Veteran
Veteran
May 19, 2007
252
106
69
doesnt need a nullable ? on the ovalue or check the value for null first like in the one that works

you can add a ? onto HelpContainer? oValue if you want the ovalue? to work
 

Far

tinmymouthpl0x
Staff member
Administrator
May 19, 2003
20,683
33
3,286
520
sounds like you might not have the latest c# versions installed to know about nullable properties.

The current code works fine on latest visual studio
 

test39857

LOMCN Rookie
Mar 26, 2024
11
0
2
sounds like you might not have the latest c# versions installed to know about nullable properties.

The current code works fine on latest visual studio
You're right. I haven't upgraded latest c# versions.
 

test39857

LOMCN Rookie
Mar 26, 2024
11
0
2
sounds like you might not have the latest c# versions installed to know about nullable properties.

The current code works fine on latest visual studio

I am still getting errors CS0131 after updating to the latest version of VS2022 17.14.25.
Which version of Visual Studio supports this feature?
 

Far

tinmymouthpl0x
Staff member
Administrator
May 19, 2003
20,683
33
3,286
520
2022 is fine, but make sure you have the latest c# and .net versions installed
 

test39857

LOMCN Rookie
Mar 26, 2024
11
0
2
2022 is fine, but make sure you have the latest c# and .net versions installed

I installed the VS2022 Community Edition.It has been updated to the latest version.
Error CS0131 will occur by default; it will only work without error if `<LangVersion>preview</LangVersion>` is manually configured in the project file.

Could you tell me which version of VS2022 to install and how to configure it?
 

Far

tinmymouthpl0x
Staff member
Administrator
May 19, 2003
20,683
33
3,286
520
If you have .net 8 + installed in visual studio it should include the correct c# versions
 
  • Like
Reactions: trancefied

Far

tinmymouthpl0x
Staff member
Administrator
May 19, 2003
20,683
33
3,286
520
You'll need to google it. If you're installed those extensions in visual studio it should compile fine.