I need to translate the following Code to an Expression and I will explain why:
results = results.Where(answer => answer.Question.Wording.Contains(term));
results is IQueryable<ISurveyAnswer>
Question is ISurveyQuestion
Wording is String
The problem is, Question is not always the name of the LINQ to SQL property.
This will give me t...
The following is my python code:
>>> item = 1
>>> a = []
>>> a.append((1,2,3))
>>> a.append((7,2,4))
>>> sums=reduce(lambda x:abs(item-x[1]),a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: <lambda>() takes exactly 1 argument (2 given)
>>>
How can I fix it?
Thanks!
...
OK, so this is more of an answer than a question, but after asking this question, and pulling together the various bits from Dustin Campbell, Egor, and also one last tip from the 'IObservable/Rx/Reactive framework', I think I've worked out a workable solution for this particular problem. It may be completely superseded by IObservable/Rx/...
I've heard that if lambda expressions are used to subscribe to an event, then this creates a weak reference to the event handler code, so it is not required to explicitly unsubscribe from the event when the subscriber dies/is no longer interested. Is this true?
E.g.
aPersion.PropertyChanged += (s, e) =>
{
...
I have a simple lambda expression that goes something like this:
x=> x.Lists.Include(l => l.Title).Where(l=>l.Title != String.Empty)
Now, if I want to add one more where clause to the expression, say, "l.InternalName != String.Empty" then what would the expression be?
...
Hi,
is there any way in .Net 2.0 to retrieve a property name from delegate?:
i => i.Name
When I call:
var property = MyMethod(i => i.Name);
I want MyMethod to return string "Name". So the value of 'property' should be "Name".
In .Net 3.5 there is simply way to do that (Expression Tree), but I have to use 2.0 Framework only.
Chris
...
Hi All,
I have a generic dictonary which is templated in the following manner:
Dictionary<object, IList<ISomeInterface>> dictionary1 = new Dictionary<object, IList<ISomeInterface>>();
If I wanted to omit certain list items against arbitrary keys (that is the items that are in the list contained within the value part of each of t...
This is a terminology question. In C#, I can do this:
delegate Stream StreamOpenerDelegate(String name);
void WorkMethod(StreamOpenerDelegate d)
{
// ...
}
void Exec1()
{
WorkMethod((x) =>
{
return File.OpenRead(x);
});
}
void Exec2()
{
StreamOpenerDelegate opener = (x) =>
{
...
Is it possible to translate the following C# code into VB.NET, using VB 9.0?
delegate Stream StreamOpenerDelegate(String name);
void Exec1()
{
WorkMethod( x => File.OpenRead(x));
}
void Exec2()
{
StreamOpenerDelegate opener = x => return File.OpenRead(x) ;
WorkMethod(opener);
}
Can I do something like this?:
Private Del...
Hi
Completly new here with a question regaridng this post : http://stackoverflow.com/questions/738139/threadpool-queueuserworkitem-with-a-lambda-expression-and-anonymous-method
Specific this :
ThreadPool.QueueUserWorkItem(
o => test.DoWork(s1, s2)
);
Can somebody please explain what the 'o' is? I can see the (in VS2008) tha...
Hi,
I'm a beginning python programmer, and I'd like someone to clarify the following behavior.
I have the following code:
env = lambda id: -1
def add(id, val, myenv):
return lambda x: val if x == id else myenv(id)
test_env = add("a", 1, env)
test_env_2 = add("b", 2, test_env)
When I look up "a" in test_env, it functions correc...
Place the following in a core assembly:
public delegate TResult Func<TResult>();
public delegate TResult Func<T, TResult>(T arg1);
public delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);
public delegate TResult Func<T1, T2, T3, TResult>(T1 arg1, T2 arg2, T3 arg3);
public delegate TResult Func<T1, T2, T3, T4, TResult>(T1 arg1, T...
I'm taking a crack at writing my first DSL for a simple tool at work. I'm using the builder pattern to setup the complex parent object but am running into brick walls for building out the child collections of the parent object. Here's a sample:
Use:
var myMorningCoffee = Coffee.Make.WithCream().WithOuncesToServe(16);
Sample with cl...
What is the way to convert the following into lambda expression?
ThreadPool.QueueUserWorkItem(delegate
{
Console.WriteLine("Current Thread Id is {0}:",
Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("I will be used as Callback");
}
);
...
Hi
I am trying to delete list of albums from Album table. Following is the syntax but it fails saying "Lambda Parameter not in scope"
Album.Delete(x => (ListOfIds).Contains(x.Id));
What am I missing here?
Please advise.
Thanks
Pankaj
...
I'm trying to do this, but it doesn't work. Some suggestions?
int test_i = 0;
DoSomethingThatTakesAgesAndNeedsToUpdateUiWhenFinished(test_i);
test_i <- still is 0 and not 3!!!
public void DoSomethingThatTakesAgesAndNeedsToUpdateUiWhenFinished(int i)
{
DisableUi();
m_commandExecutor.ExecuteWithContinuation(
() =>...
Hi there I basically need a function with the following signature
Expression<Func<T, object>> GetPropertyLambda(string propertyName)
I have made a few attempts but the problem arise when the property is nullable
it goes something like this
ParameterExpression param = Expression.Parameter(typeof(T), "arg");
Expression member = Expre...
Hi there!
Im hoping that someone has used the very excellent PagedList from Troy Goode? Im actually using it in a Winforms app, and while it does work, I have lost the ability to sort it.
Returning a PagedList, controlling the Page and Size, and binding to a DataGridView is no issue, but my biggest concern is Sorting. Now I have also ...
What is the Python code in Haskell and Lambda calculus?
def f1():
x = 77
def f2():
print x
f2
f1
My attempt in lambda calculus
\x. 77 (\x.x)
...
Is it not allowed to have a conditional operator in a lambda expression in ForEach?
List<string> items = new List<string>{"Item 1", "Item 2", "Item I Care About"};
string whatICareAbout = "";
// doesn't compile :(
items.ForEach(item => item.Contains("I Care About") ?
whatICareAbout += item + "," : whatICareAbout += "");
Compilati...