How to convert Dictionary<string, object> to Dictionary<string, string> in c#
问题 I have below code in C# Dictionary<string, object> dObject = new Dictionary<string, object>(); I want to convert dObject to Dictionary<string, string> . How can I do this? 回答1: Use the ToDictionary method: Dictionary<string, string> dString = dObject.ToDictionary(k => k.Key, k => k.Value.ToString()); Here you reuse the key from the original dictionary and you convert the values to strings using the ToString method. If your dictionary can contain null values you should add a null check before