What is the best way to do this when looping a list? I have tried to evaluate it with something like this but it wont let me evaluate bool as an "if" condition

   if (item["ShowTitle"] == true)
//do something

3 Answers 3


You can use:

 if (bool.Parse(item["ShowTitle"].ToString()) == true)


if (item["ShowTitle"].ToString() == true.ToString())

All answers are not safe, when the field is null. This can happen, when a field gets later added and already items are in this list.

This is a safe cast:

bool? showTitle = properties.ListItem["ShowTitle"] as bool?;
if (showTitle.HasValue && showTitle.Value)

  • 1
    I really like your approach and would love to have this the accepted answer!
    – Andreas
    Nov 13, 2017 at 10:35

I think this would be the cleanest way of doing it with C#:

    if ((bool)item["ShowTitle"] == true)
        //Do stuff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.