我想压缩此代码:
$scope.items = itemsResponse.data.main_themes
如果if(obj != null)
{
obj.Name = "Test";
}
有明确的方法来设置我可以写的obj
Name
没有明确的方法声明是否可以这样做?
类似的东西:
obj?.SetName("Test");
最后一个语句给出了以下错误obj?.Name = "Test"; //assign obj.Name to "Test" if obj not null, do nothing if obj is null
哪个有意义,因为The left-hand side of an assignment must be a variable, property or indexer
现在是一个可以为空的布尔值我相信。
编辑: 这个问题似乎重复了;
Using the null-conditional operator on the left-hand side of an assignment