CopyPastor

Detecting plagiarism made easy.

Score: 0.8532897505875441; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2022-12-06
by Eric Wood

Original Post

Original - Posted on 2022-12-06
by Eric Wood



            
Present in both answers; Present only in the new answer; Present only in the old answer;


I suggest .NET's TryAdd: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.tryadd?view=net-7.0
I suggest a extension method for environments where .NET's TryAdd is not available:
public static class DictionaryUtils { /// <summary> /// Prevents exception "Item with Same Key has already been added". /// </summary> public static void TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value) { if (!dictionary.ContainsKey(key)) { dictionary.Add(key, value); } } }
I suggest .NET's TryAdd: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.tryadd?view=net-7.0
I suggest a extension method for environments where .NET's TryAdd is not available:
public static class DictionaryUtils { /// <summary> /// Prevents exception "Item with Same Key has already been added". /// </summary> public static void TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value) { if (!dictionary.ContainsKey(key)) { dictionary.Add(key, value); } } }

        
Present in both answers; Present only in the new answer; Present only in the old answer;