Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:02:45+00:00 2026-06-12T03:02:45+00:00

A User in my system can have Email, Mobile or Phone and based on

  • 0

A User in my system can have Email, Mobile or Phone and based on the values passed I am checking some conditions and then setting the ContactDataStatus (which is an enum) for each. I am then checking the ContactDataStatus to determine whether the provided contact details were valid.

The enum has the following definition

public enum ContactDataStatus
    {
        ExistsButUnverified = 1, 
        ExisitsAndVerified = 2, 
        IsValid = 3, 
        IsUninitialized = 4
    }

I wrote the following if conditions to set isValid variable

    isValid = false;
    if (emailStatus == ContactDataStatus.IsValid && 
       (mobileStatus == ContactDataStatus.IsValid || 
        mobileStatus == ContactDataStatus.IsUninitialized) 
        && (phoneStatus == ContactDataStatus.IsValid || 
        phoneStatus == ContactDataStatus.IsUninitialized))
    {
        isValid = true;
    }
    else if (mobileStatus == ContactDataStatus.IsValid && 
    (emailStatus == ContactDataStatus.IsValid || 
    emailStatus == ContactDataStatus.IsUninitialized) && 
    (phoneStatus == ContactDataStatus.IsValid || 
    phoneStatus == ContactDataStatus.IsUninitialized))
    {
       isValid = true;
    }
    else if (phoneStatus == ContactDataStatus.IsValid && 
    (emailStatus == ContactDataStatus.IsValid || 
    emailStatus == ContactDataStatus.IsUninitialized) && 
    (mobileStatus == ContactDataStatus.IsValid || 
    mobileStatus == ContactDataStatus.IsUninitialized))
    {
      isValid = true;
    }

Is there a simpler/shorter way of writing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:02:46+00:00Added an answer on June 12, 2026 at 3:02 am

    It would help if you told us what the values were for the enum. It sounds like you want at least one of the values to be valid, and all of the values to either be uninitialized or valid. So one way of expressing that would be:

    var statuses = new[] { emailStatus, mobileStatus, phoneStatus };
    bool valid = statuses.Any(x => x == ContactDataStatus.IsValid) &&
                 statuses.All(x => x == ContactDataStatus.IsValid ||
                                   x == ContactDataStatus.IsUninitialized);
    

    Or if the status enum is just IsValid, IsUninitialized and (say) IsInvalid, and you knew that the values would actually be in that set, you could write:

    var statuses = new[] { emailStatus, mobileStatus, phoneStatus };
    bool valid = statuses.Any(x => x == ContactDataStatus.IsValid) &&
                 statuses.All(x => x != ContactDataStatus.IsInvalid);
    

    Also, I’d suggest that you removed the “is” prefix from each of the enum values – it’s just fluff which makes the code harder to read IMO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system whereby a user can view categories that they've subscribed to
I have make a messaging system in which user can send messages to each
I have a credit system set up on my site where user A can
I have created an inbox system. Signed in user can message other signed in
I have an admin system and a user system on my website. Some data
I am building a website templating system where multiple user can create their own
I'm interested in creating a system where the user can define the steps in
I have a user system set up in a 'users' table, and I have
I am going to be making a small user system but I have questions.
I have a user password system where I need to 1) check a user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.