compiler going crazy or am I missing something?

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

In my code I have something like that:

class RecipeFile
{
// .....
}


class OptionPanel : UserControl
{
public void Load(RecipeFile file)
{
// ....
}
}

Now when I try to compile I get the following error message:
==
Error 2 Warning as Error:
'Cook.App.Dialogs.OptionCurrentFile.Load(Cook.Data.RecipeFile)' hides
inherited member 'System.Windows.Forms.UserControl.Load'. Use the new
keyword if hiding was intended.
L:\AppSource\eCookBook\eCookBook\Dialogs\OptionCurrentFile.cs 19 15
eCookBook
==

Now, I now there is a method call
class Control
{
public void Load()
{
//....
}
}
but there should be no ambiguity at all whatsoever with Load(RecipeFile
file)

is this a know bug (happening sometimes)?
I have .NET 2.0 beta 2
 
Your OptionPanel type extends the UserControl type. UserControl has an
event named "Load" which prevents you from naming any methods this same
thing. Either you need to name your method something else like
LoadRecipe or you need to not extend the UserControl type which already
has this Load event.
 
Lloyd said:
different signature => different method..

--
Different beasts - Load on UserControl is an event, not a method.
You've never been able to have methods and events share the same name.
E.g. the following will not compile under VS2003:

Public Class Class1
Public Event Load(ByVal Arg1 As Int32)

Public Function Load(ByVal Arg1 As String)

End Function
End Class

(Sorry, tend to do most of my stuff in VB, but shouldn't take too long
to translate demo into C# :-))

Damien
 
As Damien rightfully point out....
they are different beast..... (event EventHandler Control.Load & void
Control.Load(Datat data))
(it was a typo of mine to assume to write void Control.Load())

for example the code below won't compiler (oh.. right).
======
public class T2
{
public static event EventHandler Foo;

public static void Foo(int bar)
{
Console.WriteLine("foo bar");
}

public static void Main()
{
Foo(1);
}
}
======
 
Back
Top