Skip to content

Commit a49ce6c

Browse files
Potential fix for pull request finding 'Inefficient use of ContainsKey'
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Imran Siddique <imran.siddique@microsoft.com>
1 parent 90d47aa commit a49ce6c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

agent-governance-dotnet/examples/AspNetMiddleware/Controllers/ItemsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public static ActionResult<Item> Update(int id, [FromBody] UpdateItemRequest req
7070
{
7171
lock (Sync)
7272
{
73-
if (!Store.ContainsKey(id))
73+
if (!Store.TryGetValue(id, out var existing))
7474
{
7575
return NotFound();
7676
}
7777

78-
var updated = new Item(id, request.Name ?? Store[id].Name);
78+
var updated = new Item(id, request.Name ?? existing.Name);
7979
Store[id] = updated;
8080
return Ok(updated);
8181
}

0 commit comments

Comments
 (0)