© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
22 replies
Dinny

Generic Interfaces

I am having trouble implementing a method in my class that I derived from my Generic interface using T data type.

IComparableType
using System;
using System.IO;

namespace Modeul_11
{
    public interface IComparableType<T>
    {
        public int CompareTo(T other);
    }

}
using System;
using System.IO;

namespace Modeul_11
{
    public interface IComparableType<T>
    {
        public int CompareTo(T other);
    }

}

Shape
using Modeul_11;
using System;
using System.IO;

namespace Module_11
{

    //Abstract class that extends the interface
    public abstract class Shape : IComparableType<Shape>
    {
        public abstract double Area();

        public abstract string WhatAmI();

        public int CompareTo(Shape other)
        {
            //if shape1 is less than shape 2, return -1
            // if shape 1 is greater than shape 2, return 1
            //if shape 1 and shape 2 are equal, return 0
            return 1; //FIXME
        }


    }
}
using Modeul_11;
using System;
using System.IO;

namespace Module_11
{

    //Abstract class that extends the interface
    public abstract class Shape : IComparableType<Shape>
    {
        public abstract double Area();

        public abstract string WhatAmI();

        public int CompareTo(Shape other)
        {
            //if shape1 is less than shape 2, return -1
            // if shape 1 is greater than shape 2, return 1
            //if shape 1 and shape 2 are equal, return 0
            return 1; //FIXME
        }


    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Issues with interfaces and generic classes
C#CC# / help
3y ago
Interfaces
C#CC# / help
3y ago
C# interfaces
C#CC# / help
2y ago