开发者

Combining strings with lambda expression

开发者 https://www.devze.com 2022-12-17 21:25 出处:网络
I have a string array Array1 and a string array A2.I want to combine these in a 3rd array A3 but excluding duplicate values.Can this be done through lambda expressions or only through iterating throug

I have a string array Array1 and a string array A2. I want to combine these in a 3rd array A3 but excluding duplicate values. Can this be done through lambda expressions or only through iterating through the array and checking array.Con开发者_JAVA百科tains()?


array1.Union(array2).Distinct().ToArray();


You can do the following

Dim newArray = array1.Union(array2).Distinct().ToArray()

This requires Visual Studio 2008 or higher (VB.Net 9.0).


    public static Expression<Func<T, TResult>> And<T, TResult>(this Expression<Func<T, TResult>> expr1, Expression<Func<T, TResult>> expr2)
    {
        var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
        return Expression.Lambda<Func<T, TResult>>(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
    }

    public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
    {
        var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
        return Expression.Lambda<Func<T, bool>>(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消