C#编程-95:分部类partial的使用_彭世瑜_新浪博客
彭世瑜 发布时间:2017-08-05 12:08:59 ,浏览量:1
- 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();
- }
- }
- }
1665367115
查看更多评论