enums and collections - Organizing your data - List, Regular array
Head First C#: A Learner’s Guide to Real-World Programming with C# and .NET Core (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)のChapter 8(enums and collections - Organizing your data)、p.415(Sharpen your pencil)の解答を求めてみる。
コード
Program.cs
using System;
namespace MyFirstConsoleApp
{
class Program
{
static void Main(string[] args)
{
string[] vs = new string[2];
vs[0] = "Yay!";
string b = "Bummer";
vs[1] = b;
Console.WriteLine(vs.Length);
Console.WriteLine(vs[0]);
bool foundIt = false;
foreach (string v in vs)
{
if (v == b)
{
foundIt = true;
}
}
Console.WriteLine(foundIt);
}
}
}
入出力結果(Terminal, Zsh)
2
Yay!
True