D
Dieter Pelz
Hallo,
could anyone explain why the double indexer ist called and not the
overloaded int indexer.
The Test Object is called with an int Value!
Output:
CALL Test this[double dbl] ??????????????
CALL Test this[int idx]
using System;
public class Test : TestBase
{
public override object this [int idx]
{
get {
Console.WriteLine("CALL Test this[int idx]");
return "Test[int]";
}
}
public object this[double dbl]
{
get {
Console.WriteLine("CALL Test this[double dbl]");
return "Test[double]";
}
}
public static void Main()
{
object obj;
Test tst = new Test();
int i = 2;
obj = tst;
obj = ((TestBase)tst);
Console.ReadLine();
// Output
// CALL Test this[double dbl] ??????????????
// CALL Test this[int idx]
}
};
public class TestBase
{
public virtual object this[int idx]
{
get {
Console.WriteLine("CALL TestBase this[int idx]");
return "TestBase[int]";
}
}
};
Thanks
Dieter
could anyone explain why the double indexer ist called and not the
overloaded int indexer.
The Test Object is called with an int Value!
Output:
CALL Test this[double dbl] ??????????????
CALL Test this[int idx]
using System;
public class Test : TestBase
{
public override object this [int idx]
{
get {
Console.WriteLine("CALL Test this[int idx]");
return "Test[int]";
}
}
public object this[double dbl]
{
get {
Console.WriteLine("CALL Test this[double dbl]");
return "Test[double]";
}
}
public static void Main()
{
object obj;
Test tst = new Test();
int i = 2;
obj = tst;
obj = ((TestBase)tst);
Console.ReadLine();
// Output
// CALL Test this[double dbl] ??????????????
// CALL Test this[int idx]
}
};
public class TestBase
{
public virtual object this[int idx]
{
get {
Console.WriteLine("CALL TestBase this[int idx]");
return "TestBase[int]";
}
}
};
Thanks
Dieter