Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace AlternateExpressions
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] spaceRocks = {"meteoroid", "meteor", "meteorite"};
- //use Lambda on the second argument
- //bool makesContact = Array.Exists(spaceRocks, (string s) => s == "meteorite");
- //for an even more shorter form of Lambda - remove parameter type and parentheses
- bool makesContact = Array.Exists(spaceRocks, s => s == "meteorite");
- if (makesContact)
- {
- Console.WriteLine("At least one space rock has reached the Earth's surface!");
- }
- }
- //Method won't be used since it is shrink to lambda expression in Main() method
- static bool HitGround(string s)
- {
- return s == "meteorite";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement