본문 바로가기
IT(기존 자료 보관용)

뇌를 자극하는 C# 5.0 프로그래밍 6장 연습문제 3번 답

by 공학코드 2015. 3. 24.
728x90
반응형

6장에서 익히는 메소드관련 개념 중 오버로드에 대한 개념을 묻는 문제이다. 내가 작성한 답안은 아래와 같다.


문제 1. 다음 코드에 Plus() 메소드가 double 형 매개 변수를 지원하도록 오버로딩하세요.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace practice6_3
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int a = 3;
  13. int b = 4;
  14. int resultA = 0;
  15.  
  16. Plus(a, b, out resultA);
  17.  
  18. Console.WriteLine("{0} + {1} = {2}", a, b, resultA);
  19.  
  20. double x = 2.4;
  21. double y = 3.1;
  22. double resultB = 0;
  23.  
  24. Plus(x, y, out resultB);
  25.  
  26. Console.WriteLine("{0} + {1} = {2}", a, b, resultB);
  27. }
  28. public static void Plus(int a, int b, out int c)
  29. {
  30. c = a + b;
  31. }
  32.  
  33. public static void Plus(double a, double b, out double c)
  34. {
  35. c = a + b;
  36. }
  37. }
  38. }
  39.  



728x90
반응형

댓글