类
using System;
namespace app{
class MyClass{
public static void Main(string[] args){
MyClass my = new MyClass();
Console.WriteLine(my.Calc(4));
}
int Calc( int num){
int temp =1;
for(int i =1;i<=num;i++){
temp*=i;
}
return temp;
}
}
}
17
1
using System;
2
namespace app{
3
class MyClass{
4
public static void Main(string[] args){
5
MyClass my = new MyClass();
6
Console.WriteLine(my.Calc(4));
7
}
8
int Calc( int num){
9
int temp =1;
10
for(int i =1;i<=num;i++){
11
temp*=i;
12
}
13
return temp;
14
}
15
}
16
}
静态方法:
using System;
namespace app{
class MyClass{
public static void Main(string[] args){
//MyClass my = new MyClass();
Console.WriteLine(Calc(4));
}
static int Calc( int num){
int temp =1;
for(int i =1;i<=num;i++){
temp*=i;
}
return temp;
}
}
}
17
1
using System;
2
namespace app{
3
class MyClass{
4
public static void Main(string[] args){
5
//MyClass my = new MyClass();
6
Console.WriteLine(Calc(4));
7
}
8
static int Calc( int num){
9
int temp =1;
10
for(int i =1;i<=num;i++){
11
temp*=i;
12
}
13
return temp;
14
}
15
}
16
}
动态方法:
using System;
namespace app{
class MyClass{
public static void Main(string[] args){
MyClass my = new MyClass();
Console.WriteLine(Calc(4));
}
int Calc( int num){
int temp =1;
for(int i =1;i<=num;i++){
temp*=i;
}
return temp;
}
}
}
17
1
using System;
2
namespace app{
3
class MyClass{
4
public static void Main(string[] args){
5
MyClass my = new MyClass();
6
Console.WriteLine(Calc(4));
7
}
8
int Calc( int num){
9
int temp =1;
10
for(int i =1;i<=num;i++){
11
temp*=i;
12
}
13
return temp;
14
}
15
}
16
}
参数数组
using System;
namespace app{
class MyClass{
public static void Main(string[] args){
//MyClass my = new MyClass();
//Console.WriteLine(Calc(4));
int [] a= new int [3] { 121,2,3 };
Console.WriteLine(addArr(a));
}
int Calc( int num){
int temp =1;
for(int i =1;i<=num;i++){
temp*=i;
}
return temp;
}
static int addArr( params int [] arr ){
int num=0;
for(int i=0;i<arr.Length;i++){
num+=arr[i];
}
return num;
}
}
}
26
1
using System;
2
namespace app{
3
class MyClass{
4
public static void Main(string[] args){
5
//MyClass my = new MyClass();
6
//Console.WriteLine(Calc(4));
7
int [] a= new int [3] { 121,2,3 };
8
Console.WriteLine(addArr(a));
9
}
10
int Calc( int num){
11
int temp =1;
12
for(int i =1;i<=num;i++){
13
temp*=i;
14
}
15
return temp;
16
}
17
static int addArr( params int [] arr ){
18
int num=0;
19
for(int i=0;i<arr.Length;i++){
20
num+=arr[i];
21
}
22
return num;
23
}
24
}
25
}