計算機科学のブログ

dive into C# - Statements, classes, and code - operators

Head First C#: A Learner’s Guide to Real-World Programming with C# and .NET Core (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)のChapter 2(dive into C# - Statements, classes, and code)、p.59(MINI Sharpen your pencil)の解答を求めてみる。

コード

using System;

namespace MyFirstConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            OperatorExamples();
        }

        private static void OperatorExamples()
        {
            int width = 3;
            width++;
            int height = 2 + 4;
            int area = width * height;
            Console.WriteLine(area == 24);
            string result =  "The area";
            result = result + " is " + area;
            Console.WriteLine(result == "The area is 24");
            bool truthValue = true;
            Console.WriteLine(truthValue == true);
        }
    }
}

出力結果

True
True
True