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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:01:05+00:00 2026-05-30T14:01:05+00:00

Good day all, I have a class and a property, and I have three

  • 0

Good day all,

I have a class and a property, and I have three instances of that class.

public class myclass {
  public int myproperty;
}

...

myclass inst1, inst2, inst3;

...

Now at a certain point I need to compare those three property values, and verify that they be equal or not, to end up with the least amount of values.

So if I have

inst1.myproperty = 3;
inst2.myproperty = 5;
inst3.myproperty = 3;

after the magic_function_call, I should get 3 and 5.

And if I have

inst1.myproperty = 2;
inst2.myproperty = 2;
inst3.myproperty = 2;

after the magic_function_call, I should get 2.

Albeit this is trivial per se, and can be solved with as many IF checks as needed, I was wondering which is the fastest, or more efficient way to do it, especially in light of the fact that I might need to add another variable to the check in the future.

I am in fact wondering if there is a bitwise operation that can be performed that can solve this elegantly and quickly.

Alternatively, is there an array operation that can be used to achieve the same goal? I’ve tried looking for ‘reduction’ or ‘compression’ but those keywords don’t seem to lead in the right direction.

Thanks in advance.

  • 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-30T14:01:06+00:00Added an answer on May 30, 2026 at 2:01 pm

    Here’s a quick function which doesn’t require any extra libraries and avoids the setup costs and overheads associated with LINQ:

        static int[] Reduce(IEnumerable<myclass> items)
        {
            HashSet<int> uniqueValues = new HashSet<int>();
    
            foreach (var item in items)
            {
                uniqueValues.Add(item.myproperty);
            }
    
            return uniqueValues.ToArray();
        }
    

    Pass it a collection of your myclass instances and it will return an array of unique myproperty values.

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

Sidebar

Related Questions

Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day, masters. Suppose I have a java class A: class A { public
Good day all, first of all, what am trying to do is have an
Good day to all, I have the following problem I have to convert the
Good day everyone. I have been having the same problem all day at work
Good day, all. I know that this is a pretty basic question in terms
I have a read only list that is shared across all instances of the
Good day to all, i have a problem regarding CSV parse using File Helper.
Good day, I am having an interesting problem that I cannot understand. I have
Good day to all. I have the flowing problem. I have 2 domains. On

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.