ASP.NET Basics (Part 6): Fully Function-al - Going Nowhere
(Page 6 of 8 )
The order in which arguments are passed to a function is important - the following example assumes that the name is passed as the first argument, and the place as the second.
<SCRIPT language=c# runat="server">
// define a function
string User(string name, string place)
{
return "Hello, " + name + ". How strange that we both live in " + place;
}
void Page_Load()
{
output.Text = User("Brother Moose", "Erehwon");
}
</SCRIPT>
<asp:label id=output runat="server"></asp:label>
But if you get the order wrong, you may get unexpected results. For example, if you reversed the order in which arguments are passed to the function, as below,
void Page_Load
() { output.Text = User("Erewhon", "Brother Moose"); }
this is what you'd see:
All these examples have one thing in common - the list of arguments is fixed. Look what happens if you pass an extra argument to the User() function above,
void Page_Load
() { output.Text = User("Harry the Hedgehog", "The Briar Patch", "male"); }
or miss out on a parameter when calling the function.
void Page_Load
() { output.Text = User("Harry the Hedgehog"); }
In both case, the C# compiler will complain with this ugly error:

Next: First Date >>
More ASP.NET Articles
More By Harish Kamath (c) Melonfire