Quotes help make search much faster. Example: "Practice Makes Perfect"

Tuesday, September 3, 2019

Codecademy Methods as Arguments 3/6


// Sample Solution
using System;

namespace AlternateExpressions
{
  class Program
  {
  // Method to be used as second argument
    public static bool IsLong(string word)
    {
      return word.Length > 8;
    }
     
    static void Main(string[] args)
    {
      // Array to be used as first argument
      string[] adjectives = {"rocky", "mountainous", "cosmic", "extraterrestrial"};
   
      // Call Array.Find() and
      // Pass in the array and method as arguments
      string firstLongAdjective = Array.Find(adjectives, IsLong);
     
      Console.WriteLine($"The first long word is: {firstLongAdjective}.");
    }
  }
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts