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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:29:41+00:00 2026-05-16T14:29:41+00:00

i try to compare two class comp1,comp2 i used method below: ComparerCollection(array_X, array_Y); but

  • 0

i try to compare two class comp1,comp2 i used method below: ComparerCollection(array_X, array_Y); but there are errors below. Arraylist generated from Ilist. how can i do that?

namespace GenericCollecitonComparer
{
    class Program
    {
        static void Main(string[] args)
        {
            myClass comp1 = new myClass() { ID = 1, Name = "yusuf" };
            myClass comp2 = new myClass() { ID = 1, Name = "yusufk" };
            Comparer com = new Comparer(comp1, comp2);
            Console.ReadKey();
        }
    }

    public class Comparer
    {
        public Comparer(myClass x, myClass y)
        {
            PropertyInfo[] propInfo_X = x.GetType().GetProperties();
            PropertyInfo[] propInfo_Y = y.GetType().GetProperties();
            ArrayList array_X = new ArrayList();
            ArrayList array_Y = new ArrayList();

            foreach (PropertyInfo pi in propInfo_X)
                array_X.Add(pi.GetValue(x, null));
            foreach (PropertyInfo pi in propInfo_Y)
                array_Y.Add(pi.GetValue(y, null));

           // ComparerCollection(array_X, array_Y); --> Error below


        }
        public bool ComparerCollection<T>(IList<T> xlist, IList<T> ylist)
        {
            return xlist.SequenceEqual(ylist);
        }
    }

    public class myClass
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }

}

 /*  Error  1   The type arguments for method '
             * GenericCollecitonComparer.Comparer.ComparerCollection<T>(System.Collections.Generic.IList<T>, System.Collections.Generic.IList<T>)'
             * cannot be inferred from the usage. Try specifying the type arguments explicitly.
             * 
           */

  • 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-16T14:29:41+00:00Added an answer on May 16, 2026 at 2:29 pm

    The error you receive is due to the fact ArrayList is not a generic class. You can use List<object> instead to make it work.

    An alternative implementation:

    public class Comparer
    {
        public bool AreEqual { get; private set; }
    
        public Comparer(myClass x, myClass y)
        {
            var xProperties = x.GetType().GetProperties();
            var yProperties = y.GetType().GetProperties();
    
            var xPropertiesValues = xProperties.Select(pi => pi.GetValue(x, null));
            var yPropertiesValues = yProperties.Select(pi => pi.GetValue(y, null));
    
            AreEqual = xPropertiesValues.SequenceEqual(yPropertiesValues);
        }
    }
    

    And a usage example:

    [Test]
    public void UsageExample()
    {
        myClass comp1 = new myClass() { ID = 1, Name = "yusuf" };
        myClass comp2 = new myClass() { ID = 1, Name = "yusufk" };
        myClass comp3 = new myClass() { ID = 1, Name = "yusuf" };
    
        Comparer comparerOf1And2 = new Comparer(comp1, comp2);
        Assert.IsFalse(comparerOf1And2.AreEqual);
    
        Comparer comparerOf1And3 = new Comparer(comp1, comp3);
        Assert.IsTrue(comparerOf1And3.AreEqual);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to compare two NSDate objects. But it fails all the time and
How do I compare two objects of a custom class in Objective-C? I try
i try to compare two lists with each other: ListA (a1,a2,a3,...) ListB (b1,b2,b3,...) I
I have used a stacked bar chart (with coord_flip) to try to compare distributions
I am using the compareTo method in Java to try and check if a
I try to compare Mnesia with more traditional databases. As I understand it tables
I try to get some website attribute (colour of the cell) and compare in
For example, I try to do something like this: - (BOOL)compare:(NSDecimal)leftOperand greaterThan:(NSDecimal)rightOperand { BOOL
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]

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.