A simple example that uses a parameter : Class Method : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Class Method »

 

A simple example that uses a parameter









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// A simple example that uses a parameter. 
 
using System; 
 
class ChkNum {  
  // Return true if x is prime. 
  public bool isPrime(int x) { 
    for(int i=2; i < x/2 + 1; i++) 
      if((x %i) == 0) return false; 
 
    return true; 
  } 
}  
  
public class ParmDemo {  
  public static void Main() {  
    ChkNum ob = new ChkNum(); 
 
    for(int i=1; i < 10; i++) 
      if(ob.isPrime(i)) Console.WriteLine(i + " is prime."); 
      else Console.WriteLine(i + " is not prime."); 
 
  }  
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Class Method