enums and collections - Organizing your data - List, Regular array 1
Head First C Sharp: A Learner’s Guide to Real-World Programming with C Sharp and .NET (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)の Chapter 8(enums and collections - Organizing your data)、p.415(Sharpen your pencil)の解答を求めてみる。
コード
Program.cs
string[] myList = new string[2];
p(myList);
string a = "Yay!";
myList[0] = a;
p(myList);
string b = "Bummer";
myList[1] = b;
p(myList);
int theSize = myList.Length;
Console.WriteLine(theSize);
bool foundIt = myList.Contains(b);
Console.WriteLine(foundIt);
void p(string[] strings)
{
foreach (string item in strings)
{
Console.Write(item + ", ");
}
Console.WriteLine();
}
入出力結果(Terminal, Zsh)
% dotnet run
, ,
Yay!, ,
Yay!, Bummer,
2
True
%