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

  • SEARCH
  • Home
  • 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 3316534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:28:50+00:00 2026-05-17T22:28:50+00:00

Scenario: Lets say we got to check for address lines. which includes addressline1, addressline2,Town,Country,Postcode

  • 0

Scenario:
Lets say we got to check for address lines. which includes addressline1, addressline2,Town,Country,Postcode
If any one of the property is entered, all other fields are mandatory.
If none of it is entered, the validation doesnt have to get trigged.

To achieve it, I ended up with two lines of If statement.
Like

if(AddressLine1 != null || AddressLine2 != null || Town != null || Country != null)
{
    if(AddressLine1 != null && AddressLine2 != null && Town != null && Country != null) == false
     {
          return false;
     }   
}

Note: I am using c#. Are there any language constructs i can make use of.

  • 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-05-17T22:28:51+00:00Added an answer on May 17, 2026 at 10:28 pm

    Well, the null-coalescing operator can help with the first:

    if (AddressLine1 ?? AddressLine2 ?? Town ?? Country != null)
    {
        if (AddressLine1 == null || AddressLine2 == null ||
            Town == null || Country == null)
        {
            return false;
        }
        // Presumably there's more here
    }
    

    You might want to write some helper methods though:

    if (IsAnyNonNull(AddressLine1, AddressLine2, Town, Country))
    {
        if (IsAnyNull(AddressLine1, AddressLine2, Town, Country))
        {
            return false;
        }
    }
    

    Where the utility methods would be something like:

    public static bool IsAnyNonNull(params object[] values)
    {
        return values.Any(x => x != null);
    }
    
    public static bool IsAnyNull(params object[] values)
    {
        return values.Any(x => x == null);
    }
    

    Of course, you’ve still got two if statements – but I think that’s basically necessary here anyway.

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

Sidebar

Related Questions

Here's the scenario-- you've got a JSON object on the browser, and let's say
Here is my scenario. For the example lets say that I need to return
Maybe it's not worth worrying about in this scenario, but lets say you have
Scenario Lets say I use C# WPF, and bind a Dictionary() to a DataGrids
I need to know the best approach for the following scenario lets say we
Lets take a static html page as a scenario, lets say you have a
I have following scenario: Lets say we have two different webparts operating on the
Here's the scenario I have a page lets say login.aspx having a button called
To Set up the scenario, Lets say I have 100000 rows in the table
Lets say i have the following scenario: public class A { public String createString(final

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.