Spintz

I have a form with a list box, that is meant to receive, program output. I wanted to use a default value for an argument, but that's a whole other shortcoming of C#. My understanding was that to overcome this shortcoming, you were to use overloaded functions. However, since I need thread-safe access to this listbox, I need to use delegates, and delegates seem to not support overloading. I have the following code ....

public delegate void AddOutputDelegate( string s );

public void AddOutput( string s )

{

if( this.InvokeRequired )

{

this.BeginInvoke( new AddOutputDelegate(AddOutput), new object[] { s } );

return;

}

...

}

public delegate void AddOutputDelegate( string s, EnumOutputType type );

public void AddOutput( string s, EnumOutputType type )

{

if( this.InvokeRequired )

{

this.BeginInvoke( new AddOutputDelegate(AddOutput), new object[] { type, s } );

return;

}

...

}

And this fails to compile with the following error -

error CS0102: The type 'SituationDisplayer.StatusForm' already contains a definition for 'AddOutputDelegate'

So what to do The only solution I see is to have different names for each delegate function, which actually makes the code harder to read/understand.



Re: Visual C# Language Overloading Delegates

Rashmi Gopinath

Overloading delegates is not permitted, since delegates aren't really methods.

Thanks,
Rashmi





Re: Visual C# Language Overloading Delegates

Spintz

You should be able to overload them. Kinda was my point. I understand they are objects, and delegate is a keyword, but, oh nm....

I'll have much more success convincing my bosses to forget about C# then I will to make C# better/useful.

Thanks for the feedback anwyays.