I have a DataTable/collection that is cached in memory, I want to use this as a source to generate results for an auto complete textbox (using AJAX of course).
I am evaluating various options to fetch the data quickly.
The number of items in the collection/rows in the datatable could vary from 10000 to 2,000,000. (So that we dont get di...
From what I can find on google, VB.NET only has one-statement lambdas, and not multi-statement anonymous functions. However, all the articles I read were talking about old versions of VB.NET, I couldn't find anything more recent than vs2008 beta 1 or 2.
So the question: How can I do this in VB.NET?
C# code:
private void HandleErrors( ...
A lot of questions are being answered on stackoverflow, with members specifying how to solve these real world/time problems using lambda expressions.
Are we overusing it, are we considering the performance impact of using lambda expressions?
I found few articles that explores the performance impact of lambda vs anonymous delegates vs ...
Passing two parameters to a new thread on the threadpool can sometimes be complicated, but it appears that with lambda expressions and anonymous methods, I can do this:
public class TestClass
{
public void DoWork(string s1, string s2)
{
Console.WriteLine(s1);
Console.WriteLine(s2);
}
}
try
{
TestClass te...
I can't find any way to generate an anonymous method. any ideas?
...
Imports System.Reflection
Public Class Test
Private Field As String
End Class
Module Module1
Sub Main()
Dim field = GetType(Test).GetField("Field", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
Dim test = New Test
Dim GetValue = New Func(Of Test, String)(Function(t As Test) fie...
One nice thing about anonymous methods is that I can use variables that are local in the calling context. Is there any reason why this does not work for out-parameters and function results?
function ReturnTwoStrings (out Str1 : String) : String;
begin
ExecuteProcedure (procedure
begin
Str1 := ...
Let's say I have an interface IMyInterface<T> that simply describes one function:
public interface IMyInterface<T>
{
T MyFunction(T item);
}
I could just about replace this with Func<T, T>, but I want the interface for semantic reasons. Can I define an implicit conversion between that interface and Func<T,T> such that I could pas...
I am using anonymous methods to handle events in a COM object. Once the program terminates, it appears that the resources I am using in the anonymous method are not being "closed correctly" in that I get a first chance exception (InvalidComObjectException) for every resource I was watching. I suppose this isn't a big deal, but it doesn't...
I can't be the only one getting tired of defining and naming a delegate for just a single call to something that requires a delegate. For example, I wanted to call .Refresh() in a form from possibly other threads, so I wrote this code:
private void RefreshForm()
{
if (InvokeRequired)
Invoke(new InvokeDelegate(Refresh));
...
Why do closures exist for anonymous methods? Why not just pass state into the method without the overhead of a new class being generated with the closure variables being copied in? Isn't this just a throwback to "making everything global?"
Someone talk me down, I feel like i'm missing something here...
...
Why can't you pass an anonymous method as a parameter to the BeginInvoke method ? I have the following code:
private delegate void CfgMnMnuDlg(DIServer svr);
private void ConfigureMainMenu(DIServer server,)
{
MenuStrip mnMnu = PresenterView.MainMenu;
if (mnMnu.InvokeRequired)
{
mnMnu.Begin...
var seq = Enumerable.Range(1, 10).Reverse();
var sort1 = seq.OrderBy(i => i);
var sort2 = seq.OrderBy(delegate(int i) { return i; });
i think sort2 is more explicit but sort 1 is shorter. besides that, i don't really know the difference. what is the recommended way of doing this?
...
I translated this code(it has bad side effect that it just capture the outer variable):
foreach (TaskPluginInfo tpi in Values)
{
GenerateMenu(menuStrip, tpi.MenuTree, tpi.MenuText, delegate { tpi.ShowTask() });
}
To this code(because the above is not working):
foreach (TaskPluginInfo tpi in Values)
{ ...
Hello, I've got following problem: (c#)
There is some class (IRC bot), which has method, which needs result of some event for complete (through it could be asynchronous).
Maybe not clear:
// simplified
class IRC
{
void DoSomeCommand()
{
OnListOfPeopleEvent += new Delegate(EventData e) {
if (e.IsForMe)
{
ReturnToUserSom...
Hi
See the second bit of code below.. code doesn't compile. Am trying to figure out anon methods, and I get it..
But not the example of not using anon methods which I found on the web, which doesn't compile
Using VS2008.. compiling to .NET3.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
nam...
I have the following code:
class myClass
{
private delegate string myDelegate(Object bj);
protected void method()
{
myDelegate build = delegate(Object bj)
{
var letters= string.Empty;
if (someCondition)
return build(some_obj); //This line seems to cho...
Can the following be done in C#?:
var greeting = "Hello" + function ()
{
return " World";
}() + "!";
I want to do something along the lines of this (C# pseudo code):
var cell = new TableCell { CssClass = "", Text = return delegate ()
{
return "logic goes here";
}};
Basically I want to implement in-line scoping of some logi...
I thought it would be nice to do something like this (with the lambda doing a yield return):
public IList<T> Find<T>(Expression<Func<T, bool>> expression) where T : class, new()
{
IList<T> list = GetList<T>();
var fun = expression.Compile();
var items = () => {
foreach (var item in list)
if (fun.Invoke(i...
I am sorry to ask this on here as I know it is like doing my homework for me but I have a very urgent requirement to implement a single VB.NET instance of an application on a terminal server. To do this I am using code from the Flawless Code blog. It works well, except in the code is written in C# and uses an anonymous method which is no...