C#编程-95:分部类partial的使用
分类:
文章
•
2025-01-31 08:59:40
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
-
namespace PartialTest
-
{
-
partial class Arithmetic
-
{
-
public int Factorial(int num)
-
{
-
int factorial = 1;
-
for (int i = num; i > 0; i--)
-
{
-
factorial *= i;
-
}
-
return factorial;
-
}
-
}
-
partial class Arithmetic
-
{
-
public int Square(int num)
-
{
-
return num * num;
-
}
-
}
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
Arithmetic a = new Arithmetic();
-
int num = 5;
-
Console.WriteLine("求 {0} 的阶乘:",num);
-
Console.WriteLine(a.Factorial(num));
-
Console.WriteLine("求 {0} 的平方:", num);
-
Console.WriteLine(a.Square(num));
-
Console.ReadKey();
-
}
-
}
-
}