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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:41:26+00:00 2026-06-06T08:41:26+00:00

I am trying to create a class implementing the generic IComparer of my own

  • 0

I am trying to create a class implementing the generic IComparer of my own class “Stellungen” (which translates to positions, like on a chess or checkers board).

This is what I got:

Private Class comparer(Of Stellung)
    Implements System.Collections.Generic.IComparer(Of Stellung)

    Public Function Compare(x As Stellung, y As Stellung) As Integer Implements System.Collections.Generic.IComparer(Of Stellung).Compare

    End Function

End Class

Problem is: inside the function I have no access to any fields of my class. If I start off with x. Intellisense will only give me .Equals, .GetHashCode – the methods you get on a type but not on an instance.
Visual Studio 10 also highights this, in the definition of the function the bits “x as Stellung” and “y as Stellung” are written in light blue, meaning it is a type and not an actual object.

So… what do I do?? How do I access the things I want to compare inside my class??
Thanks!

  • 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-06T08:41:28+00:00Added an answer on June 6, 2026 at 8:41 am

    The fields are probably private and that is why you cant access them.
    Make you classes implement the IComparable<T> interface. You can than use that in you comparer class.
    Here is an example of a generic comparer class that compares objects that implements IComparable<T>.

    Public Class GenericComparer(Of T As IComparable(Of T))
        Inherits Comparer(Of T)
    
        Public Overrides Function [Compare](ByVal x As T, ByVal y As T) As Integer
            If (Not x Is Nothing) Then
                If (Not y Is Nothing) Then
                    Return x.CompareTo(y)
                End If
                Return 1
            End If
            If (Not y Is Nothing) Then
                Return -1
            End If
            Return 0
        End Function
    
        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            Dim comparer As GenericComparer(Of T) = TryCast(obj,GenericComparer(Of T))
            Return (Not comparer Is Nothing)
        End Function
    
        Public Overrides Function GetHashCode() As Integer
            Return MyBase.GetType.Name.GetHashCode
        End Function
    
    End Class
    
    
    public class Stellung
       Implements IComparable(Of Stellung)
    
       Public Function CompareTo(ByVal value As Stellung) As Integer
           'Here you should be able to access all fields. 
       End Function
    End class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a generic class which new's up an instance of
I'm trying to create a generic graphics export tool which works by implementing the
I am trying to create a class in VB.NET which inherits a base abstract
I'm trying to create a point class which defines a property called coordinate. However,
I'm trying to create a generic class in PHP that will provide a way
I'm trying to create a C++ class which can work as a holder for
I'm trying to develop a generic command processor. I would like to create command
I'm trying to create JPA class implementing simple interface: public interface Task<T> { public
Background: I'm trying to create my own Vector class to assist in performing mathematical
I am trying to create a class that implements the IUnknown interface. I have

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.