using System.Collections.Generic;
public static void Main()
Console.WriteLine("Linq Testing");
var flagTrues = CreateList();
var flagFalses = CreateList(flag: false);
var flagMixed = CreateList(mixed: true);
TestListConsistency("All True", flagTrues);
TestListConsistency("All False", flagFalses);
TestListConsistency("Mixed", flagMixed);
public static List<FlaggedObject> CreateList(int count = 5, bool flag = true, bool mixed = false){
var list = new List<FlaggedObject>();
for( var i = 0; i < count; i++ ){
list.Add(new FlaggedObject{
public static void TestListConsistency(string listName, List<FlaggedObject> list){
PrintList(listName, list);
Console.WriteLine("!!! LIST EMPTY !!!");
var first = list.First();
var inconsistent = list.Any( x => x.Flag == !state );
var consistent = !inconsistent;
Console.WriteLine($"\n\n\tConsistent: {consistent}\n\n");
public static void PrintList(string listName, List<FlaggedObject> list){
var text = string.Join("\n\t",list.Select( i => i.ToString()));
Console.WriteLine($"{listName}:\n\t{text}");
public class FlaggedObject {
public string Name { get; set; }
public bool Flag { get; set; }
public override string ToString() {
return $"{Name} = {Flag}";