Click here to Skip to main content
15,887,326 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to add both x86 and x64 class library to the references in the project Pin
Pete O'Hanlon1-Feb-11 3:57
mvePete O'Hanlon1-Feb-11 3:57 
GeneralRe: How to add both x86 and x64 class library to the references in the project Pin
RobCroll1-Feb-11 12:34
RobCroll1-Feb-11 12:34 
GeneralRe: How to add both x86 and x64 class library to the references in the project Pin
Chesnokov Yuriy1-Feb-11 18:53
professionalChesnokov Yuriy1-Feb-11 18:53 
AnswerRe: How to add both x86 and x64 class library to the references in the project Pin
jschell1-Feb-11 10:40
jschell1-Feb-11 10:40 
QuestionAbstract classes and delgates Pin
igalep1321-Feb-11 2:22
igalep1321-Feb-11 2:22 
AnswerRe: Abstract classes and delgates PinPopular
DaveyM691-Feb-11 4:00
professionalDaveyM691-Feb-11 4:00 
GeneralRe: Abstract classes and delgates Pin
igalep1325-Feb-11 9:03
igalep1325-Feb-11 9:03 
GeneralRe: Abstract classes and delgates Pin
DaveyM695-Feb-11 10:57
professionalDaveyM695-Feb-11 10:57 
Ah, I see your problem.

The delegate itself can't be abstract but an instance of it (including an event) can. See the sample and test code below.
C#
using System;

class Program
{
    static void Main(string[] args)
    {
        new Test().Run();
        Console.ReadKey();
    }
}

class Test
{
    public void Run()
    {
        B b = new B();
        b.Xxx += new DelegateXxx(b_Xxx);
        C c = new C();
        c.Xxx += new DelegateXxx(c_Xxx);
        A ab = b as A;
        ab.Xxx += new DelegateXxx(ab_Xxx);
        A ac = c as A;
        ac.Xxx += new DelegateXxx(ac_Xxx);

        b.DoXxx();
        Console.WriteLine();
        ab.DoXxx();
        Console.WriteLine();
        c.DoXxx();
        Console.WriteLine();
        ac.DoXxx();
        Console.WriteLine();
    }
    private void b_Xxx(object sender, EventArgs e)
    {
        Console.WriteLine("b_Xxx Raised");
    }
    private void c_Xxx(object sender, EventArgs e)
    {
        Console.WriteLine("c_Xxx Raised");
    }
    private void ab_Xxx(object sender, EventArgs e)
    {
        Console.WriteLine("ab_Xxx Raised");
    }
    private void ac_Xxx(object sender, EventArgs e)
    {
        Console.WriteLine("ac_Xxx Raised");
    }
}

public delegate void DelegateXxx(object sender, EventArgs e);

public abstract class A
{
    public abstract event DelegateXxx Xxx;

    public abstract void DoXxx();
    protected abstract void OnXxx(EventArgs e);
}

public class B : A
{
    public override event DelegateXxx Xxx;

    public override void DoXxx()
    {
        OnXxx(EventArgs.Empty);
    }
    protected override void OnXxx(EventArgs e)
    {
        Console.WriteLine("Raising from B");
        DelegateXxx delegateXxx = Xxx;
        if (delegateXxx != null)
            delegateXxx(this, e);
    }
}

public class C : A
{
    public override event DelegateXxx Xxx;

    public override void DoXxx()
    {
        OnXxx(EventArgs.Empty);
    }
    protected override void OnXxx(EventArgs e)
    {
        Console.WriteLine("Raising from C");
        DelegateXxx delegateXxx = Xxx;
        if (delegateXxx != null)
            delegateXxx(this, e);
    }
}

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



GeneralRe: Abstract classes and delgates Pin
igalep1325-Feb-11 12:42
igalep1325-Feb-11 12:42 
QuestionFile Convert .DOCX to .png Pin
raushan_91-Feb-11 1:32
raushan_91-Feb-11 1:32 
AnswerRe: File Convert .DOCX to .png Pin
JF20151-Feb-11 2:18
JF20151-Feb-11 2:18 
AnswerRe: File Convert .DOCX to .png Pin
Eddy Vluggen1-Feb-11 6:57
professionalEddy Vluggen1-Feb-11 6:57 
GeneralRe: File Convert .DOCX to .png Pin
raushan_91-Feb-11 8:02
raushan_91-Feb-11 8:02 
GeneralRe: File Convert .DOCX to .png Pin
Eddy Vluggen1-Feb-11 20:27
professionalEddy Vluggen1-Feb-11 20:27 
Questioncheck if value is null Pin
arkiboys1-Feb-11 1:01
arkiboys1-Feb-11 1:01 
AnswerRe: check if value is null Pin
Bernhard Hiller1-Feb-11 1:09
Bernhard Hiller1-Feb-11 1:09 
GeneralRe: check if value is null Pin
arkiboys1-Feb-11 1:12
arkiboys1-Feb-11 1:12 
GeneralRe: check if value is null Pin
Dave Kreskowiak1-Feb-11 1:53
mveDave Kreskowiak1-Feb-11 1:53 
AnswerRe: check if value is null Pin
Richard MacCutchan1-Feb-11 1:10
mveRichard MacCutchan1-Feb-11 1:10 
GeneralRe: check if value is null Pin
arkiboys1-Feb-11 1:28
arkiboys1-Feb-11 1:28 
GeneralRe: check if value is null Pin
Pete O'Hanlon1-Feb-11 1:43
mvePete O'Hanlon1-Feb-11 1:43 
GeneralRe: check if value is null Pin
arkiboys1-Feb-11 1:50
arkiboys1-Feb-11 1:50 
GeneralRe: check if value is null Pin
Richard MacCutchan1-Feb-11 3:19
mveRichard MacCutchan1-Feb-11 3:19 
QuestionGetWindowText Funcation not working Fine iF Application Title is Unicode or Other Language. Pin
Anubhava Dimri1-Feb-11 0:17
Anubhava Dimri1-Feb-11 0:17 
AnswerRe: GetWindowText Funcation not working Fine iF Application Title is Unicode or Other Language. Pin
Pete O'Hanlon1-Feb-11 0:22
mvePete O'Hanlon1-Feb-11 0:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.