Click here to Skip to main content
15,914,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error handling code.. Pin
MarkB77720-Mar-08 20:53
MarkB77720-Mar-08 20:53 
Generalinserting and retrieving data from a datarow in C# Pin
salon20-Mar-08 19:36
salon20-Mar-08 19:36 
Questionhow to get index value in imagebutton gridview using .net with c# Pin
sugunavathysubramanian20-Mar-08 19:10
sugunavathysubramanian20-Mar-08 19:10 
GeneralDelegate problem Pin
MarkB77720-Mar-08 17:22
MarkB77720-Mar-08 17:22 
GeneralRe: Delegate problem Pin
Christian Graus20-Mar-08 18:54
protectorChristian Graus20-Mar-08 18:54 
GeneralRe: Delegate problem Pin
MarkB77720-Mar-08 19:41
MarkB77720-Mar-08 19:41 
GeneralRe: Delegate problem Pin
Christian Graus20-Mar-08 20:48
protectorChristian Graus20-Mar-08 20:48 
GeneralGeneric Collections and Interfaces (Returning a collection of interfaces) Pin
dfa_geko20-Mar-08 17:05
dfa_geko20-Mar-08 17:05 
Hi Everyone,

I'm trying to write a graph interface where I have objects that can act manipulated like a graph.

Ok, so I have a graph interface (IGraph) that has a method to return a generic list of interfaces ( List<IVertex> ). However, the class the implements the IGraph interface a list of a concrete class Point ( List<Point> ) which implements IVertex. I can't return it unless if I create a new generic List<IVertex> and do a deep copy.

<br />
public interface IGraph<br />
{<br />
  List<IVertex> GetVertices();<br />
}<br />
<br />
public interface IVertex<br />
{<br />
  int X { get; set; }<br />
  int Y { get; set; }<br />
}<br />
<br />
public class Point : IVertex<br />
{<br />
  private int _x;<br />
  private int _y;<br />
<br />
  // Implement property of IVertex (Not shown)<br />
}<br />
<br />
public class ConcreteGraph : IGraph<br />
{<br />
  private List<Point> _points;<br />
   <br />
  public ConcreteGraph()<br />
  {}<br />
<br />
  public List<IVertex> GetVertices()<br />
  {<br />
    return _points;  // Error: Cannot implicitly convert type List<point> to List<ivertex><br />
  }<br />
}<br />
</ivertex></point>


Any one have any ideas? I could do like the following code:

<br />
List<ivertex> list = new List<IVertex>();<br />
foreach (Point p in _points)<br />
{<br />
  list.Add((IVertex)p);<br />
}<br />
</ivertex>


But it doesn't seem too efficient. Is there a way of doing this that is more efficient?

Thanks!

dfa_geko
GeneralRe: Generic Collections and Interfaces (Returning a collection of interfaces) Pin
Steve Echols20-Mar-08 19:04
Steve Echols20-Mar-08 19:04 
Generalthread priority Pin
George_George20-Mar-08 16:29
George_George20-Mar-08 16:29 
GeneralRe: thread priority Pin
Paul Conrad21-Mar-08 8:11
professionalPaul Conrad21-Mar-08 8:11 
GeneralRe: thread priority Pin
George_George21-Mar-08 21:16
George_George21-Mar-08 21:16 
GeneralRe: thread priority Pin
Paul Conrad22-Mar-08 5:23
professionalPaul Conrad22-Mar-08 5:23 
GeneralRe: thread priority Pin
George_George23-Mar-08 3:06
George_George23-Mar-08 3:06 
GeneralRe: thread priority Pin
Paul Conrad23-Mar-08 5:29
professionalPaul Conrad23-Mar-08 5:29 
GeneralRe: thread priority Pin
George_George23-Mar-08 19:37
George_George23-Mar-08 19:37 
GeneralRe: thread priority Pin
Paul Conrad24-Mar-08 4:25
professionalPaul Conrad24-Mar-08 4:25 
GeneralRe: thread priority Pin
George_George24-Mar-08 4:40
George_George24-Mar-08 4:40 
GeneralStrange stack trace Pin
Winkles20-Mar-08 15:56
Winkles20-Mar-08 15:56 
GeneralRe: Strange stack trace Pin
Guffa21-Mar-08 1:17
Guffa21-Mar-08 1:17 
GeneralRe: Strange stack trace Pin
Winkles21-Mar-08 6:21
Winkles21-Mar-08 6:21 
GeneralRe: Strange stack trace Pin
Winkles21-Mar-08 9:13
Winkles21-Mar-08 9:13 
Generalhelp with Databinding for visual studio .net in c # Pin
atonynh20-Mar-08 15:47
atonynh20-Mar-08 15:47 
GeneralRe: help with Databinding for visual studio .net in c # Pin
Christian Graus20-Mar-08 18:56
protectorChristian Graus20-Mar-08 18:56 
QuestionCan someone please tell me why the if Loop in my codes not working. Pin
ADTC#20-Mar-08 14:06
ADTC#20-Mar-08 14:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.