2018年8月15日水曜日

開発環境

初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)日向 俊二 (翻訳)、オライリージャパン)の7章(クラスとオブジェクト)、7.10(練習問題)、練習7-1.を取り組んでみる。

コード

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 1.2;
            double b = 3.4;
            Math math = new Math();
            double[] vs = {
                math.Add(a, b),
                math.Subtract(a, b),
                math.Multiply(a, b),
                math.Divide(a, b) };

            foreach (var item in vs)
            {
                Console.WriteLine(item);
            }
        }
    }
    public class Math
    {
        public double Add(double a, double b)
        {
            return a + b;
        }
        public double Subtract(double a, double b)
        {
            return a - b;
        }
        public double Multiply(double a, double b)
        {
            return a * b;
        }
        public double Divide(double a, double b)
        {
            return a / b;
        }
    }
}

入出力結果(コマンドプロンプト)

4.6
-2.2
4.08
0.352941176470588
続行するには何かキーを押してください . . .

0 コメント:

コメントを投稿