using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
public class MainClass{
public static void Main(string[] args){
List<String> TestData = new List<String>();
var ThisQuery = from TheData in TestData select TheData;
foreach (var ThisElement in ThisQuery.DefaultIfEmpty())
Console.WriteLine(ThisElement);
TestData.Add("One");
TestData.Add("Two");
TestData.Add("Three");
foreach (var ThisElement in ThisQuery.DefaultIfEmpty())
Console.WriteLine(ThisElement);
}
}
public static class MyStrings
{
public static IEnumerable<string> DefaultIfEmpty(this IEnumerable<string> source)
{
if (source.Count<String>() > 0)
return source;
else
{
List<string> DefaultValue = new List<string>();
DefaultValue.Add("Empty");
return DefaultValue;
}
}
}
|