C
C#

Generic Interfaces

Generic Interfaces

DDinny11/21/2023
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
}


}
}
NOTE: IK IT LOOKS WEIRD BUT MY PROF CODES THIS WAY, SO DON'T WORRY ABOUT HOW FUNKY SOME THINGS LOOK. HE'S OLD SCHOOL my issue is where the commented "if statements" are in my shape class the example he gave was " if x.CompareTo(y) < 0, return -1" I am unsure how to do that here since there's no data fields
AAngius11/21/2023
I guess it's supposed to compare areas? That Area() method I guess serves as some sort of a Java-ism for a getter
DDinny11/21/2023
omg slay i remember u u helped me out a lot last time ur like super smart yes it is comparing areas
JJimmacle11/21/2023
your professor doesn't know that IComparable<T> already exists? PepeHmmm
DDinny11/21/2023
heres the instructions he gave
No description
DDinny11/21/2023
if this will help it's an intro to generic interfaces and T datatypes so im sure he's already aware omg oops wrong class hold ong
DDinny11/21/2023
No description
DDinny11/21/2023
this is the instructions for the shape class if this helps
JJimmacle11/21/2023
yeah so you just have to implement CompareTo for Shape
DDinny11/22/2023
i was able to figure it out tysm !

Looking for more? Join the community!

C
C#

Generic Interfaces

Join Server
Want results from more Discord servers?
Add your server
Recommended Posts
Manual setup of OpenTelemetry with/without Microsoft.Extensions.Hosting in a Console applicationAfter seeing Aspire I have decided to see how OpenTelemetry, and i first created a console applicatiQuestion regarding learning.. stuff.Might be weirdge for some, but I've never really understood the perception and grasping of learning.[EF Core 8] Many-to-many relationship with payloadHi all, I am trying to create a many-to-many relationship as described in https://learn.microsoft.coDo you know any C# code editors where I can run code?Under 500 MB✅ Getting back main functionRecently after updating to CS8 (didnt update in a long time), and creating a console app there is noCookie Clicker project for schoolso i have a problem i need to fix a bug on a picture. I use mouse down and mouse up events to resize✅ else statement executing regardless of whether I want it to or not, windows form appI've created a simple windows form app to create shapes on a bitmap, I have a function that gives anMaui adb additional parametersI need to test a Maui applicaiton on a physical android device. The app recorded a error, to see whHow to let compiler know that List is not null?Hi community! I have the following extension method:, which checks if the source is not null and if✅ How to Fix MSB6006 yasm.exe exited with code -1073741515 on Cosmos Kernel✅ Issue during pushing a commit to GitHub from VS CodeHi friends, I'm working on a project using `VS Code`, I used `VS Code` to clon that project from my✅ Need help understanding inheritance with constructorsI know about constructors partially (I'm used to Unity's MonoBehaviour so constructors are mostly suHow to get the data of an adapter using MQTTnetThis is the documentation: https://docs.service.sicon.eco/sicon.os/2023.19.x/adapter-protocol-smqtt Converting from a string to a generic method invocationLooking for design patterns to help solve this problem I’m having at work. The situation is that we Auto refresh inside windows formTeam , We are using windows form c#. Is there any library for auto refresh (need to few logic eve✅ Fresh Install of Windows, I'm Getting Weird Errors (NETSDK1/NU1012, and DEP0700)Anyone know what might be happening here in my Maui Blazor Hybrid projects? For the older project object reference not set to instance of object on a static method callso im trying to use an opengl binding package (Veldrid.OpenGLBinding) but, when i call any of the meWeb API model classesI'm coding a webshop using ASP.NET Core Web API for the backend and Next.js for the frontend. I'm deInvalidate JWT-Tokens on logout and password change.I have an ASP.net Web api that handles user interaction. For authentification I use JWT Tokens. I reDynamically enable/disable a route in ASP.NET 7?Is there a way to dynamically enable/disable a route in ASP.NET 7? I'd like to be able to enable/dis