Skip to content

Commit

Permalink
added test case for #764
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Oct 20, 2023
1 parent 3ab761b commit ff6ff35
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion TestCases/InheritanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,44 @@ public static void InheritanceTest23()
if (cls5 is InterfaceTest2)
throw new Exception();
}
public static void InheritanceTest24()
{
ListSub list = new ListSub();
float res = list.Update(0, 1);
if (res < 10)
throw new Exception();
}
class ListSub : AbstractBase
{
List<AbstractBase> children = new List<AbstractBase>();
public ListSub()
{
for (int i = 0; i < 10; i++)
children.Add(new ListSub2());
}

public override float Update(float a, float b)
{
float baseVal = a;
foreach (var i in children)
{
baseVal += i.Update(baseVal, b);
}
return baseVal;
}
}

class ListSub2 : AbstractBase
{
public override float Update(float a, float b)
{
return a + b;
}
}
abstract class AbstractBase
{
public abstract float Update(float a, float b);
}

class TestExplicitInterface : IDisposable
{
Expand Down Expand Up @@ -552,7 +590,7 @@ void InheritanceTest06_Sub<T>() where T:MyClass
T obj = Activator.CreateInstance(typeof(T)) as T; //这样写错误
//MyClass obj = Activator.CreateInstance(typeof(T)) as MyClass; //这样写正确
obj.Reg();
}
}

interface IMy
{
Expand Down

0 comments on commit ff6ff35

Please sign in to comment.