JavaScript/jQuery equivalent of LINQ Any()
These days you could actually use Array.prototype.some (specced in ES5) to get the same effect: array.some(function(item) { return notValid(item); });
These days you could actually use Array.prototype.some (specced in ES5) to get the same effect: array.some(function(item) { return notValid(item); });
Ok, so the answer was derived from some other posts about this problem and it is: If your ViewData contains a SelectList with the same name as your DropDownList i.e. “submarket_0”, the Html helper will automatically populate your DropDownList with that data if you don’t specify the 2nd parameter which in this case is the … Read more
Sure – you just need the ToListAsync() method, which is in the System.Linq.Async NuGet package. Here’s a complete example: Project file: <Project Sdk=”Microsoft.NET.Sdk”> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include=”System.Linq.Async” Version=”4.0.0″ /> </ItemGroup> </Project> Code: using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { IAsyncEnumerable<string> sequence = … Read more
One way would be to create a singleton-sequence out of the item (such as an array), and then Concat it onto the original: image.Layers.Concat(new[] { image.ParentLayer } ) If you’re doing this really often, consider writing an Append (or similar) extension-method, such as the one listed here, which would let you do: image.Layers.Append(image.ParentLayer) .NET Core … Read more
using System; using System.Collections.Generic; using System.Linq; class C { public static void Main() { var a = new []{ “First”, “Second”, “Third” }; System.Console.Write(string.Join(“,”, a)); } }
Because it’s not. Indexing is covered by IList. IEnumerable means “I have some of the powers of IList, but not all of them.” Some collections (like a linked list), cannot be indexed in a practical way. But they can be accessed item-by-item. IEnumerable is intended for collections like that. Note that a collection can implement … Read more
With .NET 4.0 (or the 3.5 version of System.Interactive from Rx), you can use Zip(): var dic = keys.Zip(values, (k, v) => new { k, v }) .ToDictionary(x => x.k, x => x.v);
You are looking for Enumerable.Empty<T>(). In other news the Java empty list sucks because the List interface exposes methods for adding elements to the list which throw exceptions.
Yes. Do the following: Collection<string> myCollection = new Collection<string>; foreach (string curString in myCollection.Skip(3)) //Dostuff Skip is an IEnumerable function that skips however many you specify starting at the current index. On the other hand, if you wanted to use only the first three you would use .Take: foreach (string curString in myCollection.Take(3)) These can … Read more
You can use Cast<T>() or OfType<T> to get a generic version of an IEnumerable that fully supports LINQ. Eg. IEnumerable objects = …; IEnumerable<string> strings = objects.Cast<string>(); Or if you don’t know what type it contains you can always do: IEnumerable<object> e = objects.Cast<object>(); If your non-generic IEnumerable contains objects of various types and you … Read more