FindAll vs Where extension-method

Well, FindAll copies the matching elements to a new list, whereas Where just returns a lazily evaluated sequence – no copying is required. I’d therefore expect Where to be slightly faster than FindAll even when the resulting sequence is fully evaluated – and of course the lazy evaluation strategy of Where means that if you … Read more

Impossible to use ref and out for first (“this”) parameter in Extension methods?

You have to specify ref and out explicitly. How would you do this with an extension method? Moreover, would you really want to? TestClass x = new TestClass(); (ref x).ChangeWithExtensionMethod(otherTestClass); // And now x has changed? Or would you want to not have to specify the ref part, just for the first parameter in extension … Read more

Extension methods on a struct

Yes, you can add extension methods on structs. As per the definition of extension method, you can easily achieve it. Below is example of extension method on int namespace ExtensionMethods { public static class IntExtensions { public static bool IsGreaterEqualThan(this int i, int value) { return i >= value; } } }

F# extension methods in C#

[<System.Runtime.CompilerServices.Extension>] module Methods = [<System.Runtime.CompilerServices.Extension>] let Exists(opt : string option) = match opt with | Some _ -> true | None -> false This method could be used in C# only by adding the namespace (using using) to the file where it will be used. if (p2.Description.Exists()) { …} Here is a link to the … Read more

The operation cannot be completed because the DbContext has been disposed error

This question & answer lead me to believe that IQueryable require an active context for its operation. That means you should try this instead: try { IQueryable<User> users; using (var dataContext = new dataContext()) { users = dataContext.Users.Where(x => x.AccountID == accountId && x.IsAdmin == false); if(users.Any() == false) { return null; } else { … Read more