計算機科学のブログ

types and references - Getting the reference - number, integers, floating-point types

Head First C#: A Learner’s Guide to Real-World Programming with C# and .NET Core (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)のChapter 4(types and references - Getting the reference)、p.161(Sharpen your pencil)の解答を求めてみる。

入出力結果(Terminal, Zsh, csi(C# Interactive))

% csi
Microsoft (R) Visual C# Interactive Compiler version 3.6.0-4.20224.5 ()
Copyright (C) Microsoft Corporation. All rights reserved.

Type "#help" for more information.
> int i;
> i == 0
true
> long l;
> l == 0;
(1,1): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
> l
0
> l == 0
true
> flot f;
(1,1): error CS0246: The type or namespace name 'flot' could not be found (are you missing a using directive or an assembly reference?)
> float f;
> f == 0
true
> f
0
> float f;
> f
0
> double d;
> d == 0.0
true
> d
0
> decimal m;
> m = 0
true
> m
0
> byte b;
> b == 0
true
> b
0
> char c
. ;
> c == ''
(1,6): error CS1011: Empty character literal
> c
'\0'
> c == '\0'
true
> string s;
> s == ""
false
> s
null
> bool t;
> t == false
true
> t
false
> %