C# - Creating an overloaded method where one int uses a fixed value and the other receives a value -


I am trying to set the value of an overloaded method to 1, but I wanted the original to remain raw I am {} Public zero method1 (string string 1, decimal decimal 1, int int1) {} public zero method 1 (string string 1, decimal decimal 1, int int1 = 1) {}

I get the following error:

  & gt; Error 2 type 'Application1.Application' already defines a member named 'Method1' with the same parameter type  

this int int1 = 1 . In the second version of the law, I want always equal to 1 int1 , but first I want the user to get the value entered, and therefore is now crude for

< P> Sorry if asked before, but after an hour of searching I have not found any results for this. If I am missing something here, please tell me, I will try to give a better description or more details.

The problem is that you have got two methods with the same signature. The simplest solution is to remove the last parameter from the second overload, and only call the first overload with a hard-coded value for the last argument:

  Public Zero Method1 ( String string1, decimal decimal 1, int int1) {// what you actually want to do here} Public Zero Method1 (string string 1, decimal decimal 1) {Method1 (string1, decimal1, 1); }  

(If your two methods do not mean to get the same result, then you have to give them different names to start them.)

If you want to use instead of optional parameters, you can only do a method:

  public zero method1 (string string 1, decimal decimal 1, int Int1 = 1) {// whatever it is ...} // Watch, there is no second overload  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -