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.");
}
}
Related examples in the same category