jag har ett litet problem.
Jag har ett interface "Node" och 2 klasser som implementerar det "klass1" och "klass2" och vill ha dessa i en gemensam lista.
Om du verkligen har gjort det du skriver så ska det fungera.
Men jag tror vi behöver se all kod (eller ett minimalt exempel där du får felet) för att komma vidare.
Kompileringsfelen indikerar att din klass1 inte alls implementerar interfacet Node.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace WindowsFormsApplication1
{
interface Node : IXmlSerializable
{
void setSize();
Size getSize();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace WindowsFormsApplication1
{
class GruppNode : Node
{
public void setSize()
{
}
public Size getSize()
{
return new Size(0,0);
}
public void WriteXml(XmlWriter writer)
{
}
public void ReadXml(XmlReader reader)
{
}
public XmlSchema GetSchema()
{
return (null);
}
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var nodes = new List<Node> {new SymbolNode(), new GruppNode()};
foreach (var node in nodes)
{
Console.WriteLine(string.Format("Node is GruppNode: {0}", node is GruppNode));
Console.WriteLine(string.Format("Node is SymbolNode: {0}", node is SymbolNode));
Console.WriteLine();
}
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
}
interface Node : IXmlSerializable
{
void setSize();
Size getSize();
}
class GruppNode : Node
{
public void setSize()
{
}
public Size getSize()
{
return new Size(0, 0);
}
public void WriteXml(XmlWriter writer)
{
}
public void ReadXml(XmlReader reader)
{
}
public XmlSchema GetSchema()
{
return (null);
}
}
class SymbolNode : Node
{
public void setSize()
{
}
public Size getSize()
{
return new Size(0, 0);
}
public void WriteXml(XmlWriter writer)
{
}
public void ReadXml(XmlReader reader)
{
}
public XmlSchema GetSchema()
{
return (null);
}
}
}