delegates and virtual functions
Tech-Archive recommends: Speed Up your PC by fixing your registry
Do delegates don't respect polymorphisms -- why?
say in this example:
using System;
public delegate string FirstDelegate (int x);
abstract class Base
{
public abstract string Foo(int );
public void Dispatch()
{
FirstDelegate del=new FirstDelegate (Foo);
del(5);
}
}
class Derived
{
public override string Foo(int x)
{
return " "+x;
}
}
class Runner
{
public static void Main()
{
Derived d=new Derived();
d.Dispatch(); //trys to delegate bases
}
}
The same thing happens when Base is NOT abstract class and Foo is
declared as virtual....
Is there a rule don't mix delegates and runtime polymorphism???
.
Relevant Pages
- Re: CodeDOM, const strings and abstract base classes
... I may be misunderstanding what you want to do, but could you make the string ... protected override string MagicString { ... > I'd like to declare the const in the abstract class is because I want to ... The methods in the base class will parse the contents of the const ... (microsoft.public.dotnet.languages.csharp) - Re: Threading on Functions returning values
... explaination given below by you. ... delegate string MyDelegate; ... Just cast the return value from Invoke() to whatever you need, and as long as the cast matches the actual return type of the invoked method, it will work fine. ... If the above does not solve the issue, I recommend that you read the MSDN documentation on delegates as well as the Control.Invokemethod. ... (microsoft.public.dotnet.framework) - abstract inheritance and interfaces
... I've got a problem with inheriting an interface in an abstract class. ... String[] GetAll; ... public String GetName() ... (microsoft.public.dotnet.csharp.general) - Re: is it possible to get delegates from properties directly?
... If your design truely needs the delegates & using a string to retrieve them ... Public Property Name As String ... Public Sub SetName ... (microsoft.public.dotnet.languages.vb) - RE: best way to randomly access my class members
... I continued this question in a thread about Delegates, ... If I'm passed data in random order of responseIDs, is there a way to access ... Public Text As String ... Public Property Q001As Q001resp ... (microsoft.public.dotnet.languages.vb) |
|