从 TDictionary class 获取所有键作为单个字符串

get all keys as single string from TDictionary class

有没有更聪明的方法(使用更少的代码)从 TDictionary 获取所有键作为单个字符串,逗号分隔

var
  FDicList : TDictionary <String, Integer>;
  KeyStrList: TStringlist;
  KeyName: string;
begin

  /// result as comma text
  KeyStrList := TStringlist.Create;
  try
    for KeyName in FDicList.Keys do
      KeyStrList.Add(KeyName);

    All_keys_as_string := KeyStrList.CommaText;
  finally
    KeyStrList.Free;
  end; 

end;

只要键本身不包含逗号,您就可以这样写:

All_keys_as_string := string.Join(',', FDicList.Keys.ToArray);