ASP.NET
  Home arrow ASP.NET arrow Page 3 - ASP.NET Basics (Part 6): Fully Function-al
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

ASP.NET Basics (Part 6): Fully Function-al
By: Harish Kamath (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2003-11-11

    Table of Contents:
  • ASP.NET Basics (Part 6): Fully Function-al
  • The Right Spirit
  • Turning Up the Heat
  • Sweet Tooth
  • Passing the Buck
  • Going Nowhere
  • First Date
  • Flavor of the Month

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    ASP.NET Basics (Part 6): Fully Function-al - Turning Up the Heat


    (Page 3 of 8 )

    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.";


    </SCRIPT>
     <?xml:namespace prefix asp /><asp:label id=output runat="server"></asp:label>



    The output is as follows:

    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.";


    </SCRIPT>
     <asp:label id=output runat="server"></asp:label>



    The output is as follows:



    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.



    More ASP.NET Articles
    More By Harish Kamath (c) Melonfire


     

    ASP.NET ARTICLES

    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT