当我组合2个哈希集时,HashSet.Union vs 之间的区别是什么 HashSet.Unionwith.
我想这样组合:
HashSet<EngineType> enginesSupportAll = _filePolicyEvaluation.EnginesSupportAll;
enginesSupportAll = enginesSupportAll != null ? new HashSet<EngineType>(engines.Union(enginesSupportAll)) : enginesSupportAll;
Run Code Online (Sandbox Code Playgroud)
这个例子的最佳方法是什么?为什么?
我想在我的控制器中将param作为可选项,但是swagger根据需要显示它.
我的控制器看起来像:
[HttpGet("{name}")]
[SwaggerResponse((int)HttpStatusCode.OK)]
[SwaggerResponse((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> GetPolicy(string name)
{
if (string.IsNullOrEmpty(name))
{
return BadRequest("Name is empty");
}
try
{
CRUDPolicyResponse crudPolicyResponse = await _managementOperations.CRUDPolicy(CRUDType.Read, name, null);
if (!crudPolicyResponse.OperationSucceeded)
{
return StatusCode((int)HttpStatusCode.BadRequest, crudPolicyResponse.Message);
}
if (crudPolicyResponse.FileMetadataPolicy == null)
{
return NotFound($"Policy name doesn't exists NAME: {name}");
}
return Ok(crudPolicyResponse.FileMetadataPolicy);
}
catch (Exception ex)
{
_log.Error("Error while trying to save file meta data policy", ex);
return StatusCode((int)HttpStatusCode.InternalServerError, ex);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图像这样更改为默认值:string name = null但不工作/

所以名称字符串是必需的,我不能使用名称为空.
我试图通过这个解决方案来解决我的问题, 使得int可以为空