Logo         Community
The Company
Your Account
Contact Us
ASP.NET Basics (part 6): Fully Function-al
Modularize your code in C# by abstracting it into functions.

| Turning Up The Heat |

By default, when a function is invoked, it always generates a "return value". This return value can either be a special return type called "void", or a value explicitly returned via the "return" statement. I have already demonstrated the use of "void" for my "guaranteedPickMeUp" function, which does not return any value. But how about a function that does return a value?

Here's an example of how a return value works.

<script language="c#" runat="server">

// define a function
double tempConv()
        double celsius = 35;
        double fahrenheit;
        fahrenheit = (celsius * 1.8) + 32;
        return fahrenheit;

void Page_Load()

string result;

result = tempConv().ToString();
output.Text = "35 Celsius is " + result + " Fahrenheit.";

<head><title>Turning Up The Heat</title></head>
<asp:label id="output" runat="server" />

The output is as follows:

Output image

In this case, the value of the last expression evaluated within the function is assigned to the variable "result" when the function is invoked from within the program. Note that the return value must be explicitly specified within the function definition via the "return" statement, and the data type of this return value must be specified in the first line of the function definition, before the name; failure to do either of these will cause the C# compiler to barf all over your screen.

To illustrate this, consider the output if the "return" statement is eliminated from the function definition above.

Output image

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback