Basically, I was wondering if there already exists a way to do:
Right now I have:
if (func())
{
dictionary.add(KeyA, ValueA);
}
if (func2(myString))
{
dictionary.add(KeyB, ValueB);
}
if (anonymous predicate)
{
dictionary.Add(KeyC, ValueC);
}
Does there already exist a way to do:
dictionary.AddIf(KeyA, ValueA, ...)
//etc?
I added using System.Linq but it isn’t in there.
There’s nothing built in – I don’t find this syntax intuitive but you could write your own extension method(s) to help you out:
Sample usage: