dotnet/roslyn

Improve IDE0059 code fix for TryGetValue

開放

#34,446 建立於 2019年3月26日

 (0 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-IDEFeature - IDE0059help wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Version Used: Visual Studio 2019 RC

Steps to Reproduce:

string Method(IDictionary<int, string> map, int key)
{
  if (map.TryGetValue(key, out var text))
  {
    return map[key];
  }

  return null;
}

Apply the code fix for IDE0059 reported for the unused variable text.

Expected Behavior:

string Method(IDictionary<int, string> map)
{
  if (map.TryGetValue(key, out var text))
  {
    return text;
  }

  return null;
}

Actual Behavior:

string Method(IDictionary<int, string> map)
{
  if (map.TryGetValue(key, out _))
  {
    return map[key];
  }

  return null;
}

貢獻者指南