The code below does not compile and I cannot figure out why. The compiler
issues the error: "Cannot convert type 'CustomCollecti on' to
System.Collecti ons.Generic.Lis t<IGraphableRec ord>".
1.
I have a IGraphableRecor d interface. The class CustomGraphReco rd implements
the interface (so, CustomGraphReco rd "is a" IGraphableRecor d).
2.
I have a CustomCollectio n class which is a generic list of CustomGraphReco rd
objects.
3.
OK, now I have an interface, IGraphableTable , which specifies a method
GetGraphData () that returns a Generic list of IGraphableRecor d objects. I
also have a class which attempts to implement the interface. It contains a
private variable (_collectionOfR ecords) of type, CustomCollectio n. I am
trying to satisfy the interface requirement of implementing the
GetGraphData() method by returning the variable _collectionOfRe cords.
However, this is where the above mentioned compile error occurs.
I have tried a couple variations, but have been uncessfull at getting a
compile. Can anyone provide ideas on what is wrong and how to fix it?
Gary
using System;
using System.Collecti ons.Generic;
using System.Text;
public interface IGraphableRecor d
{
int X { get;}
int Y { get;}
}
public class CustomGraphReco rd : IGraphableRecor d
{
int _x, _y;
public int X { get { return _x; } }
public int Y { get { return _y; } }
public string Name { get { return "Custom"; } }
}
public class CustomCollectio n : List<CustomGrap hRecord>
{
}
public interface IGraphableTable
{
List<IGraphable RecordGetGraphD ata();
}
public class CustomGraphUnit : IGraphableTable
{
CustomCollectio n _collectionOfRe cords = new CustomCollectio n();
public List<IGraphable RecordGetGraphD ata()
{
return (List<IGraphabl eRecord>) _collectionOfRe cords;
}
}
issues the error: "Cannot convert type 'CustomCollecti on' to
System.Collecti ons.Generic.Lis t<IGraphableRec ord>".
1.
I have a IGraphableRecor d interface. The class CustomGraphReco rd implements
the interface (so, CustomGraphReco rd "is a" IGraphableRecor d).
2.
I have a CustomCollectio n class which is a generic list of CustomGraphReco rd
objects.
3.
OK, now I have an interface, IGraphableTable , which specifies a method
GetGraphData () that returns a Generic list of IGraphableRecor d objects. I
also have a class which attempts to implement the interface. It contains a
private variable (_collectionOfR ecords) of type, CustomCollectio n. I am
trying to satisfy the interface requirement of implementing the
GetGraphData() method by returning the variable _collectionOfRe cords.
However, this is where the above mentioned compile error occurs.
I have tried a couple variations, but have been uncessfull at getting a
compile. Can anyone provide ideas on what is wrong and how to fix it?
Gary
using System;
using System.Collecti ons.Generic;
using System.Text;
public interface IGraphableRecor d
{
int X { get;}
int Y { get;}
}
public class CustomGraphReco rd : IGraphableRecor d
{
int _x, _y;
public int X { get { return _x; } }
public int Y { get { return _y; } }
public string Name { get { return "Custom"; } }
}
public class CustomCollectio n : List<CustomGrap hRecord>
{
}
public interface IGraphableTable
{
List<IGraphable RecordGetGraphD ata();
}
public class CustomGraphUnit : IGraphableTable
{
CustomCollectio n _collectionOfRe cords = new CustomCollectio n();
public List<IGraphable RecordGetGraphD ata()
{
return (List<IGraphabl eRecord>) _collectionOfRe cords;
}
}
Comment