C#
  Home arrow C# arrow Page 2 - C# Simplified, part 2: Methods & Programmi...
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 
Mobile Linux 
App Generation ROI 
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? 
C#

C# Simplified, part 2: Methods & Programming Constructs
By: Anand Narayanaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 16
    2005-05-10

    Table of Contents:
  • C# Simplified, part 2: Methods & Programming Constructs
  • Declaring methods with parameters
  • Overloading Methods
  • Different types of programming constructs in C#
  • Different types of looping statements in C#
  • break Statement

  • 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


    C# Simplified, part 2: Methods & Programming Constructs - Declaring methods with parameters


    (Page 2 of 6 )

    As explained earlier, you can declare methods with parameters. You can supply any number of parameters inside a method. The parameter should include a valid data type followed by a variable, as shown in listing 2.3. 

    Listing 2.3

    void display(int x, int y)

    {

    //Statements goes here

    }

    An important point which you must keep in mind is that you have to supply relevant values while calling the method, as shown in listing 2.4. Otherwise, there will be compilation errors.

    Listing 2.4

    d.display(200,400);

    The listing given below illustrates this concept with a help of a simple program.

    Listing 2.5 

    using System;

    class Params

    {

    // A Method named display() declared with two parameters x and y of type integer

    void display(int x,int y)

    {

    Console.WriteLine(x);

    Console.WriteLine(y);

    }

    public static void Main()

    {

    //Object of the class created

    Params prm = new Params();

    //Method display() called by passing two integer values

    prm.display(700,900);

    }

    }

    In the above listing, a method named display() is declared with two integer parameters. The method also gives necessary statements for printing the value of those variables. Note that we haven't given any value to the variables while declaring the method. Inside the Main() method, an object of the class is created, and the method display() is called by passing two values. If you are not passing any values while accessing the method, there will be compilation errors.

    More C# Articles
    More By Anand Narayanaswamy


     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





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