Use a parameter in a member function : Method Parameter « Class « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Class » Method Parameter 
7.6.4.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== 0return 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.")
 
  }  
}
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.
7.6.Method Parameter
7.6.1.How Arguments Are Passed
7.6.2.Parameter modifiers
7.6.3.Pass int value to a function
7.6.4.Use a parameter in a member function
7.6.5.A member function with two arguments
7.6.6.Pass int without 'out' and 'ref'
7.6.7.Pass integer by ref
7.6.8.ref parameters
7.6.9.Pass integer value by value
7.6.10.params int[] args
7.6.11.Use out for int type
7.6.12.Creating a method with a reference argument.
7.6.13.Variable arguments to a method in C#.
7.6.14.Method parameter hides the class member field
7.6.15.C# Parameter Modifiers
7.6.16.use of 'outer variable' in anonymous method
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.