[Solved] How can i Overload Method in c#? [closed]


To overload, you specify a method of the same type and name but with different parameters. for example:

public int Foo(int bar)
{
  return bar*2
}

public int Foo(string bar)
{
  return bar.Length*2;
}

Then when you reference the Foo method, you get 1 overload, the string parameter one.

HOWEVER,

The age part of your type isn’t a method, it’s a field. A field is different as it can be accessed and edited (dependent on the getters and setters) when you instantiate a type (var foo = new Person()).

6

solved How can i Overload Method in c#? [closed]