65.9K
CodeProject is changing. Read more.
Home

The Elegant Art of Programming

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.90/5 (3 votes)

May 21, 2012

CPOL
viewsIcon

11685

This is an alternative for "The Elegant Art of Programming"

Introduction

I thought that the tip was really more interesting, but please do not use such title and then depress myself with that.

An elegant solution is:

List<int> myList = new List<int>() {1,2,1};

Console.WriteLine("All numbers are{0} the same",
        myList.Any((i) => i != myList[0])? " not":String.Empty);

Console.ReadKey();

Just a line, not any loops, and multiple unnecessary stuff.