Similar Threads
1. In need of an IProgressDialog Bug workaround
2. IProgressDialog
hello,
When I'm using IProgressDialog and StartProgressDialog method, I must
wait almost 10 seconds to see my progressdialog.
I load animation, but why this is so slow?
m.
3. Vtale interfaces , disp interfaces and Dual Interface ???
4. CallbackContract with inherited interfaces -> Base interface n
5. C# Interface to C DLL Interface Design Questions - CSharp/C#
6. Interface features implemented without using Interface
see this demo code I created just to verify the topic being discussed here.
using System;
using System.Collections;
namespace InterfaceDemo
{
public class Car:IComparable
{
public string name;
public int speed;
Car() { }
public Car(String N, int S)
{
name = N;
speed = S;
}
//see this provides Clonability without explicit IClonable implementation
public object Clone()
{
return this.MemberwiseClone();
}
public override string ToString()
{
return string.Format("Name: {0}, Speed: {1}", this.name,
this.speed);
}
int IComparable.CompareTo(Object o)
{
Car c = (Car)o;
return ((this.speed > c.speed) ? 1 : -1);
}
}
public class Garage
{
public Car[] carArray;
public Garage()
{
carArray = new Car[4];
carArray[0] = new Car("Rusty", 30);
carArray[1] = new Car("Clunker", 55);
carArray[2] = new Car("Zippy", 30);
carArray[3] = new Car("Fred", 30);
}
//Provides functionality of foreach access to the class
//Note: no IEnumerable implemented
public IEnumerator GetEnumerator()
{
return carArray.GetEnumerator();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace InterfaceDemo
{
class Program
{
static void Main(string[] args)
{
Garage carLot = new Garage();
foreach (Car c in carLot)
{
Console.WriteLine("{0} is going {1} MPH", c.name, c.speed);
}
Car c1 = new Car("OriginalCar", 100);
Console.WriteLine(c1.ToString());
Car c2 = (Car)c1.Clone();
Console.WriteLine("Cloned Object: {0}", c2.ToString());
Garage g = new Garage();
try
{
Array.Sort(g.carArray); //calls IComparable.CompareTo from
Car implicitly
}
catch (Exception e)
{
Console.WriteLine("->Exception: {0}", e.Message);
}
Console.ReadLine();
}
}
}
7. Derived class Interface method needs to call Base Class Interface Method - CSharp/C#
8. Deriving a more specific interface from a generic interface
Hi all - I'm sure I'm being brain-dead here - and I think the answer is 'you
can't do that', but I thought I would try.
I have an interface that is Generic, with two type arguments. I want to
create a second interface that specifices the second type argument. I also
want to have objects implement that second interface without having to
implement the more generic methods that are inherited from the first. This
is especially evident when I implement multiple interfaces:
Some code will illustrate the problem:
// Base Type
interface I
{}
// 'Base' manager
interface IBase<T1, T2> where T2 : ICollection<T1>
{
T2 GetT1s();
}
// Base type collection
interface ICol<T1> : ICollection<T1> where T1 : I {}
// Derived type
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I {}
// Actual entities to manage
class A : I {}
class B : I {}
// Manager
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// Note the explicit implementation here
ICol<B> IBase<B, ICol<B>>.GetT1s()
{...}
}
I would really like to get rid of the 'IBase<B, ICol<B>>' - I would like to
use IDerived<B>, but this doesn't work. if I change IDerived to look like
this:
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I
{ new ICol<T1> GetT1s();}
Then I need to implement two forms of the method in the manager:
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// I want the following method...
ICol<B> IDerived<B>.GetT1s()
{...}
// But not this one!
ICol<B> IBase<B, ICol<B>>.GetT1s()
{...}
}
What am I doing wrong? I would love to only have to implement
IDerived<B>.GetT1s();
Thanks,
Phil