New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of Lambda
C#
public static void Copy(string sourceDirName, string destDirName, bool excludeSubdirectories)
{
    // Style #1: fluent
    Guard.MethodArgument("sourceDirName").IsNotNullOrEmpty(sourceDirName);
    Guard.MethodArgument("destDirName").IsNotNullOrEmpty(destDirName, "The destination directory is required!");
 
    // Style #2: lambdas and expressions
    Guard.Argument.IsNotNullOrWhiteSpace(()=>sourceDirName);
    Guard.Argument.IsNotNullOrWhiteSpace(()=>destDirName, "The destination directory is required!");
by Al Gonzalez   May 24, 2010 @ 8:58pm
67 Views
1 comments
 
C#
private void Test()
{
    List<string> messages = new List<string>();
    messages.Add("Hello");
    messages.Add("world");
    messages.Add("!");
 
    // Vroegah
    foreach (var msg in messages)
        Echo(msg);
by Rutger   April 01, 2010 @ 7:29am
85 Views
no comments
 
C#
// usage:
// var constructor = GetConstructor<Foo>();
// IFoo foo = constructor();
 
 
private static Func<T> GetConstructor<T>() where T : class, new()
{
    ConstructorInfo constructorInfo = typeof(T).GetConstructor(new Type[0]);
    return Expression.Lambda<Func<T>>(Expression.New(constructorInfo))
                .Compile();
by tarasn   March 26, 2010 @ 12:21pm
Tags: lambda
68 Views
no comments
 
C#
var _Offspring = _Context.Users   
        .SelectMany(x => x.Offspring).Distinct();
by Jerry Nixon   March 05, 2010 @ 8:44am
173 Views
no comments
 
C#
[TestMethod]
public void CanGetValueItemfromCollection()
{
    var col = new Collection<string> {"Hello", "World"};
    var testItem = col.GetValueItem(c => c.Equals("World"));
    Assert.AreEqual(testItem, "World");
}
 
[TestMethod]
public void CanGetReferenceItemfromCollectionByProperty()
by Bob Baker   December 18, 2009 @ 12:01pm
83 Views
no comments
 
C#
/// <summary>
/// Find an object in a value-type collection.
/// </summary>
/// <typeparam name="T">Type of collection.</typeparam>
/// <param name="collection">The collection to search.</param>
/// <param name="isMatch">The Predicate to test to find the collection item.</param>
/// <returns>The collection item.</returns>
public static T GetValueItem<T>(this ICollection<T> collection, Predicate<T> isMatch)
{
    foreach (var item in collection)
by Bob Baker   December 18, 2009 @ 12:00pm
80 Views
no comments
 
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate