写4个同名方法,实现两个整数、两个实数,一个实数一个整数,一个整数一个实数之间的求和。在主调函数中调用这4个方法计算相关的值。(方法的重载)

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication7
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             //整数相加
14             int a = 1;
15             int b = 3;
16             int sum = Test(a, b);
17             Console.WriteLine("整数相加:{0}+{1}={2}", a, b, sum);
18             Console.WriteLine();
19             //实数相加
20             double c = 2.5;
21             double d = 5.2;
22             double sum1 = Test(c, d);
23             Console.WriteLine("实数数相加:{0}+{1}={2}", c, d, sum1);
24             Console.WriteLine();
25             //实数加整数
26             double e = 3.5;
27             int f = 6;
28             double sum2 = Test(e, f);
29             Console.WriteLine("实数加整数:{0}+{1}={2}", e, f, sum2);
30             Console.WriteLine();
31             //整数加实数
32             int g = 8;
33             double h = 9.9;
34             double sum3 = Test(g, h);
35             Console.WriteLine("整数加实数:{0}+{1}={2}", g, h, sum3);
36             Console.WriteLine();
37 
38             Console.ReadKey();
39         }
40 
41         static int Test(int a, int b)
42         {
43             int sum = a + b;
44             return sum;
45         }
46         static double Test(double a, double b)
47         {
48             double sum = a + b;
49             return sum;
50         }
51         static double Test(double a, int b)
52         {
53             double sum = a + b;
54             return sum;
55         }
56         static double Test(int a, double b)
57         {
58             double sum = a + b;
59             return sum;
60         }
61     }
62 }

 

posted @ 2015-12-19 00:34  翻滚吧炒鸡蛋  阅读(444)  评论(0编辑  收藏  举报