×

c# · level 1 · unit 6 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Ask an array what it holds, or loop to find the best.

To an array for one item, bring in a second toolbox with . Then arrays learn a new trick: fridge.Contains("jam") gives true if the item is there, false if not.

To find the biggest number, search with a loop. Keep the first item in a box called best. Each time you meet a bigger one, put that in best instead.

When the loop ends, best holds the biggest item. Swap > for < and the same trick finds the smallest.

using System;
using System.Linq;

string[] fridge = { "milk", "cheese", "jam" };
Console.WriteLine(fridge.Contains("jam"));
if (!fridge.Contains("eggs"))
{
    Console.WriteLine("Add eggs to the shopping list.");
}

Each using line sits at the top, before the blank line, one toolbox per line.