PC Review


Reply
Thread Tools Rate Thread

When a class is both an inherited class of another, and alsoimplements an interface method

 
 
Curious
Guest
Posts: n/a
 
      14th Aug 2009
The code below doesn't compile (after I added ": IComparable" on the
first line). Any advice on how to get it compiled?

public class LongTermLimitOnBuy : LongTermLimit : IComparable
{
public LongTermLimitOnBuy(double price, int shares) : base
(price, shares)
{
}

// Sort by Price in descending order
public int CompareTo(object other)
{

if (null == other)
{
throw new ArgumentNullException("other");
}
if (other is LongTermLimitOnBuy)
{
return (this.Price - (other as
LongTermLimitOnBuy).Price >= 0 ? 1 : 0);
}
else
{
throw new InvalidOperationException("Bad type");

}
}
}
 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      14th Aug 2009
Try:

public class LongTermLimitOnBuy : LongTermLimit, IComparable


"Curious" <(E-Mail Removed)> wrote in message
news:107297ff-460f-4c0f-9b92-(E-Mail Removed)...
> The code below doesn't compile (after I added ": IComparable" on the
> first line). Any advice on how to get it compiled?
>
> public class LongTermLimitOnBuy : LongTermLimit : IComparable
> {
> public LongTermLimitOnBuy(double price, int shares) : base
> (price, shares)
> {
> }
>
> // Sort by Price in descending order
> public int CompareTo(object other)
> {
>
> if (null == other)
> {
> throw new ArgumentNullException("other");
> }
> if (other is LongTermLimitOnBuy)
> {
> return (this.Price - (other as
> LongTermLimitOnBuy).Price >= 0 ? 1 : 0);
> }
> else
> {
> throw new InvalidOperationException("Bad type");
>
> }
> }
> }



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
inherited class instead of expected class in interface implementation parez Microsoft C# .NET 2 9th May 2008 04:26 PM
Can a base class method return an object of an inherited class typ Ethan Strauss Microsoft C# .NET 12 12th Jan 2008 12:41 AM
Derived class Interface method needs to call Base Class Interface Method Kevin Frey Microsoft C# .NET 2 1st Dec 2006 06:57 PM
Compare class names of interface inherited classes =?Utf-8?B?Sm9hY2hpbQ==?= Microsoft C# .NET 3 20th Apr 2006 01:05 PM
Best way to call inherited method with var of base class? =?Utf-8?B?UGhpbGlwIFdhcm5lcg==?= Microsoft VB .NET 6 16th Nov 2004 05:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.