c# parameters question
I am new to c# and need help understandi开发者_高级运维ng what going on in the following function
public bool parse(String s)
{
table.Clear();
return parse(s, table, null);
}
where table is a Dictionary. I can see that is is recursive but how is parse being passed three params when it is defined to take just a string?
EDIT: how do I delete a question? parse has been overloaded facepalm
it is overloaded parse
exists that accepts 3 arguments.
No, it is not recursive.
It's a totally different function.
In C#, and also C++, different functions can have the same name. This is called 'overloading'
There has to be another definition in your code that has a parse method that accepts three parameters. Right click on the "parse" on the line with the return and select "Go to Definition" in visual studio to find it.
Method overloading in class based Object Oriented Languages is a very helpful tool. Methods are like functions (they have parameters, they return a value unless they are void and they do some things), but they are part of a class (if they are static) or an object. A method is identified by a method signature. If you define two methods with the same name for a class or the objects of the class, but the parameter list is different, they become two different methods, with the same name.
Benefits: 1.) If some methods are basically doing the same, you'll know from the start this, because you give them exactly the same name. 2.) You can use overloading to solve many problems in a simple way which are very difficult to manage under languages like C.
Recursivity would happen if you called parse("foo") there, because that would call the same function.
The parse function is overloading. In overloading same function can do different work depend upon parameter.
Second parse method excepting 3 arguments.
精彩评论