I have this code snippet and I need to check the dictionary before accessing it.
How can I verify the existence of the key before trying to access it ?
foreach (var publication in publications)
{
var publicationLinks = links[publication.PublicationId];
var litigationLink = publicationLinks.FirstOrDefault(x => x.ProcessoId.HasValue);
if (litigationLink != null)
{
litigationLinks[publication.PublicationId] = litigationLink.ProcessoId.Value;
continue;
}
var contactLink = publicationLinks.FirstOrDefault(x => x.ContatoId.HasValue);
if (contactLink != null)
{
contactsLinks[publication.PublicationId] = contactLink.ContatoId.Value;
}
}