Hi everybody,
I have a compile error within my code which I cant seem to understand why I am getting it. Could somebody explain why this is an error? Is there any way to do this?
Thanks!
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; namespace ConsoleApplication
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
MyChildClass2<MoreValues> a = <span style="color:Blue; new MyChildClass2<MoreValues>();
a.Name.Value1 = <span style="color:#A31515; "Value1Value";
a.Name.Value2 = <span style="color:#A31515; "Value2Value";
MyParentClass2<IValue> b = a; <span style="color:Green; // Compile error
Console.WriteLine(b.Name.Value1);
}
}
<span style="color:Blue; interface IValue
{
<span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MoreValues : IValue
{
<span style="color:Blue; public <span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; }
<span style="color:Blue; public <span style="color:Blue; string Value2 { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyParentClass
{
<span style="color:Blue; public <span style="color:Blue; virtual IValue Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyChildClass : MyParentClass
{
<span style="color:Blue; public <span style="color:Blue; override IValue Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyParentClass2<X> <span style="color:Blue; where X : IValue
{
<span style="color:Blue; public X Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyChildClass2<X> : MyParentClass2<X> <span style="color:Blue; where X : MoreValues
{
}
}
[/code]
View the full article
I have a compile error within my code which I cant seem to understand why I am getting it. Could somebody explain why this is an error? Is there any way to do this?
Thanks!
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; namespace ConsoleApplication
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
MyChildClass2<MoreValues> a = <span style="color:Blue; new MyChildClass2<MoreValues>();
a.Name.Value1 = <span style="color:#A31515; "Value1Value";
a.Name.Value2 = <span style="color:#A31515; "Value2Value";
MyParentClass2<IValue> b = a; <span style="color:Green; // Compile error
Console.WriteLine(b.Name.Value1);
}
}
<span style="color:Blue; interface IValue
{
<span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MoreValues : IValue
{
<span style="color:Blue; public <span style="color:Blue; string Value1 { <span style="color:Blue; get; <span style="color:Blue; set; }
<span style="color:Blue; public <span style="color:Blue; string Value2 { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyParentClass
{
<span style="color:Blue; public <span style="color:Blue; virtual IValue Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyChildClass : MyParentClass
{
<span style="color:Blue; public <span style="color:Blue; override IValue Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyParentClass2<X> <span style="color:Blue; where X : IValue
{
<span style="color:Blue; public X Name { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; class MyChildClass2<X> : MyParentClass2<X> <span style="color:Blue; where X : MoreValues
{
}
}
[/code]
View the full article