Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

I have a method called public int sum(int a,int b).

And i had made use of the sum() method in all other pages in my project.

But now i wanted to add one new parameter called int c i.e., sum(int a,int b,int c).

If i add it them i am getting error that

"
VB
Error   2   No overload for method 'sum' takes 4 arguments    C:\Windows Data\gv_info\contactus.aspx.cs   43  28  C:\Windows Data\gfo\
.


So is there any way to solve this problem.

As i worked on php function, there i used to call a function as sum(int a,int b,int c=0).

In ASP.NET i wanted to know...

Plz help me
Posted
Comments
Emre Ataseven 7-Jun-14 11:21am    
how do you call your new method?
PRAKASH_N 7-Jun-14 11:23am    
sum(1,2,3)

In C# (provided it's V4 or above) you can provide optional arguments:
C#
public int Sum(int a, int b, int c = 0)
   {
   ...
And it'll work fine.

Or, you could use the params keyword:
C#
public int Sum (params int[] vars)
   {
   int sum = 0;
   foreach (int i in vars)
      {
      sum += i;
   ...
You can then call it with one or more values:
C#
sum = Sum(7);
sum = Sum(1, 2, 3, 4, 5, 6, 7, 8, 9);
 
Share this answer
 
Comments
PRAKASH_N 7-Jun-14 11:36am    
HI..

i am sorry i am dealing with specific function or method like

public int getData(int id,int regid,int CRN_id,int cust_id)
{

// get the id
// do some calculation
//update the table with CRN



///finally delete cust_id from table
....
....
return result;
}

In this case
Quote:
No overload for method 'sum' takes 4 arguments
The error message is quite clear. You don't have a sum method or a overload sum method to deal with 4 parameters.

Either change the existing sum method signature or define one overload of sum method accepting 4 parameters.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900