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 6247387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:51:43+00:00 2026-05-24T12:51:43+00:00

Say I have 3 char variables, a , b and c . Each one

  • 0

Say I have 3 char variables, a, b and c.
Each one can be '0', which is a special case and means it matches every char.

So if a is '0', I only need to check if b == c.
I want to check if a == b == c, but found the implementation in C# goes chaotic and lengthy.

Is there any creative or pretty solution you can offer?

update

for performance driven, take Erik A. Brandstadmoen’s approach.
for simplicity, use M4N’s apprach, also i did some modification: !(query.Any() && query.Distinct().Skip(1).Any())

  • 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-24T12:51:44+00:00Added an answer on May 24, 2026 at 12:51 pm

    Something like this should work for any number of char values:

    public class Comparer
    {
        public static bool AreEqualOrZero(params char[] values)
        {
            var firstNonZero = values.FirstOrDefault(x => x != '0');
            return values.All(x => x == firstNonZero || x == '0');
        }
    }
    

    Passes the following unit tests:

    [TestClass()]
    public class ComparerTest
    {
    
        [TestMethod()]
        public void Matches_With_Wildcard()
        {
            char[] values = {'0', '1', '1', '1'};
            Assert.IsTrue(Comparer.AreEqualOrZero(values));
        }
    
        [TestMethod()]
        public void Matches_With_No_Wildcard()
        {
            char[] values = {'1', '1', '1', '1'};
            Assert.IsTrue(Comparer.AreEqualOrZero(values));
        }
    
        [TestMethod()]
        public void Matches_With_Only_Wildcards()
        {
            char[] values = {'0', '0', '0'};
            Assert.IsTrue(Comparer.AreEqualOrZero(values));
        }
    
        [TestMethod()]
        public void Matches_With_Zero_Length()
        {
            char[] values = {};
            Assert.IsTrue(Comparer.AreEqualOrZero(values));
        }
    
        [TestMethod()]
        public void Matches_With_One_Element()
        {
            char[] values = {'9'};
            Assert.IsTrue(Comparer.AreEqualOrZero(values));
        }
    
        [TestMethod()]
        public void Matches_With_One_Wildcard_And_Nothing_Else()
        {
            char[] values = {'0'};
            Assert.IsTrue(Comparer.AreEqualOrZero(values));
        }
    
        [TestMethod()]
        public void Does_Not_Match_On_NonEqual_Sequence_No_Wildcard()
        {
            char[] values = {'1', '2', '1', '1'};
            Assert.IsFalse(Comparer.AreEqualOrZero(values));
        }
    
        [TestMethod()]
        public void Does_Not_Match_On_NonEqual_Sequence_With_Wildcard()
        {
            char[] values = {'1', '2', '1', '0'};
            Assert.IsFalse(Comparer.AreEqualOrZero(values));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two char variables, and later on I want to concatenate
How can i copy multiple char* variables into one char* at single instance operation.
Let's say I have a char* str = 0123456789 and I want to cut
If we have char *val = someString; and then say if(val){ .... } what
Say I have the following C++: char *p = new char[cb]; SOME_STRUCT *pSS =
Let's say I have some pointers called: char * pChar; int * pInt; I
I have allocated a chunk of memory of type char and size is say
I have a single hexadecimal character, say char c = 'A'; What's the proper
Say, i have binary protocol, where first 4 bits represent a numeric value which
Say I have defined a variable like this (C++): static const char str[] =

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.