We help IT Professionals succeed at work.
Get Started

How to handle a null dictionary value?

thinklings
thinklings asked
on
186 Views
Last Modified: 2015-12-13
Hi,

I have the following code that manipulates a dictionaries value. The dictionary list is fieldValues. The purpose is that I check if the value contains a certain string and if it does, I replace it with the value of another dictionary value.


foreach (var val in fieldValues)
{                    
          if (val.Value.Contains(("signer" + sig.Value).ToString()))
          {
                    fieldValues[val.Key] = val.Value.Replace((sig.Value).ToString(), (sig.Key).ToString());
          }                                        
}

Open in new window


Although this shouldn't happen, sometimes the dictionary value is null and the program crashes. I just want to know how I should handle the null dictionary values so that the foreach lp
Comment
Watch Question
Freelance programmer / Consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 5 Answers and 25 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE