Use a parameter in a member function : Method Parameter : Class C# Examples


C# Examples » Class » Method Parameter »

 

Use a parameter in a member function









    
using  System;  
  
class  ChkNum  {    
    //  Return  true  if  x  is  prime.  
    public  bool  isPrime(int  x)  {  
        for(int  i=2;  i  <=  x/i;  i++)  
            if((x  %i)  ==  0)  return  false;  
  
        return  true;  
    }  
}    
    
class  MainClass  {    
    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.");  
  
    }    
}
    
   
  
   



Output

1 is prime.
2 is prime.
3 is prime.
4 is not prime.
5 is prime.
6 is not prime.
7 is prime.
8 is not prime.
9 is not prime.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Method Parameter