In C# you can not set default values for method parameters like in Delphi. So you can not make a method like this:
private int DoSomething(int Start, int End = -1);
The only way to 'simulate' this is using an overloaded method.
What is overloading?
Overloading gives you the possibility to name two methods the same, but they must have different parameters. So in a way you can simulate the default parameters.
In Delphi you must mark this methods as overloaded in C# you can write your methods without any keyword.
When using overloading for 'default' purposes it should be considered that if you don't do this clever you will be put up with two methods with almost te same code, so it is wise to follow the rule that the method with the fewest parameters calls the other one.
So in the DoSomething method:
(A very stupid function indeed :) )
private int DoSomething(int Start, int End);
{
if (End !=- 1)
return Start + End;
else
return Start + 1000;
}
private int DoSomething(int Start);
{
return DoSomething(Start, -1);
//So do not do this, you will end up with two same code paths:
// return Start + 1000;
}
Programming blogs containing .NET, C#, LINQ, Objective-C and Delphi experiences
Subscribe to:
Post Comments (Atom)
Use an image as your UIBarButtonItem
Using an image as your UIBarButtonItem in your navigationcontroller bar can only be achieved by using a common UIButton as the BarButtonItem...
-
In ASP.NET it is easy to set the prefered authentication method in the web.config file. For external websites this is set mostly to Forms ...
-
Using an image as your UIBarButtonItem in your navigationcontroller bar can only be achieved by using a common UIButton as the BarButtonItem...
-
How to get, for example, all the hyperlinks from a webpage, which is loaded in your iPhone app using the UIWebView control? (Xcode's web...
No comments:
Post a Comment