開発環境
- OS: macOS High Sierra - Apple
- IDE(統合開発環境): Visual Studio for Mac
- プログラミング言語: C#
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の9章(デバッグ)、9.6(練習問題)、問題9-2.を取り組んでみる。
コード
using System;
namespace Sample9_2
{
class Program
{
public void Run()
{
int myInt = 42;
float myFloat = 9.685f;
Console.WriteLine(
"呼び出す前:\n myInt の値: {0}\n myFloat の値: {1}",
myInt, myFloat);
Multiply(ref myInt, ref myFloat);
Console.WriteLine(
"呼び出した後:\n myInt の値: {0}\n myFloat の値: {1}",
myInt, myFloat);
Console.Write("{0}, {1}", 42 * 2 / 3 * 2, 9.685 * 2 / 3 * 2);
}
private static void Multiply(ref int theInt, ref float theFloat)
{
theInt *= 2;
theFloat *= 2;
Dvide(ref theInt, ref theFloat);
}
private static void Dvide(ref int theInt, ref float theFloat)
{
theInt /= 3;
theFloat /= 3;
Add(ref theInt, ref theFloat);
}
private static void Add(ref int theInt, ref float theFloat)
{
theInt += theInt;
theFloat += theFloat;
}
static void Main(string[] args)
{
Program p = new Program();
p.Run();
}
}
}
入出力結果(Terminal)
呼び出す前: myInt の値: 42 myFloat の値: 9.685 呼び出した後: myInt の値: 56 myFloat の値: 12.91333 56, 12.9133333333333 Press any key to continue...
0 コメント:
コメントを投稿