Tutorial by Examples: any

Any

Returns true if the collection has any elements that meets the condition in the lambda expression: var numbers = new[] {1,2,3,4,5}; var isNotEmpty = numbers.Any(); Console.WriteLine(isNotEmpty); //True var anyNumberIsOne = numbers.Any(n => n == 1); Console.WriteLine(anyNumberIsOne); //Tr...
Enumerable.Select returns an output element for every input element. Whereas Enumerable.SelectMany produces a variable number of output elements for each input element. This means that the output sequence may contain more or fewer elements than were in the input sequence. Lambda expressions passe...
var allTasks = Enumerable.Range(1, 5).Select(n => new Task<int>(() => n)).ToArray(); var pendingTasks = allTasks.ToArray(); foreach(var task in allTasks) task.Start(); while(pendingTasks.Length > 0) { var finishedTask = pendingTasks[Task.WaitAny(pendingTasks)]; Conso...
var random = new Random(); IEnumerable<Task<int>> tasks = Enumerable.Range(1, 5).Select(n => Task.Run(async() => { Console.WriteLine("I'm task " + n); await Task.Delay(random.Next(10,1000)); return n; })); Task<Task<int>> whenAnyTask = Tas...
var sequenceOfSequences = new [] { new [] { 1, 2, 3 }, new [] { 4, 5 }, new [] { 6 } }; var sequence = sequenceOfSequences.SelectMany(x => x); // returns { 1, 2, 3, 4, 5, 6 } Use SelectMany() if you have, or you are creating a sequence of sequences, but you want the result as one long sequen...
The SelectMany linq method 'flattens' an IEnumerable<IEnumerable<T>> into an IEnumerable<T>. All of the T elements within the IEnumerable instances contained in the source IEnumerable will be combined into a single IEnumerable. var words = new [] { "a,b,c", "d,e&quo...
reduce will not terminate the iteration before the iterable has been completly iterated over so it can be used to create a non short-circuit any() or all() function: import operator # non short-circuit "all" reduce(operator.and_, [False, True, True, True]) # = False # non short-circu...
Let's look at a more complex example that contains a one-to-many relationship. Our query will now contain multiple rows containing duplicate data and we will need to handle this. We do this with a lookup in a closure. The query changes slightly as do the example classes. IdNameBornCountryIdCountry...
int i = 42; i = i++; /* Assignment changes variable, post-increment as well */ int a = i++ + i--; Code like this often leads to speculations about the "resulting value" of i. Rather than specifying an outcome, however, the C standards specify that evaluating such an expression produc...
ob_start(); $user_count = 0; foreach( $users as $user ) { if( $user['access'] != 7 ) { continue; } ?> <li class="users user-<?php echo $user['id']; ?>"> <a href="<?php echo $user['link']; ?>"> <?php echo $user...
The standard (section 23.3.7) specifies that a specialization of vector<bool> is provided, which optimizes space by packing the bool values, so that each takes up only one bit. Since bits aren't addressable in C++, this means that several requirements on vector are not placed on vector<bool...
Special care needs to be taken when there is a possibility that an array become an empty array when it comes to logical operators. It is often expected that if all(A) is true then any(A) must be true and if any(A) is false, all(A) must also be false. That is not the case in MATLAB with empty arrays....
To ignore a file foo.txt in any directory you should just write its name: foo.txt # matches all files 'foo.txt' in any directory If you want to ignore the file only in part of the tree, you can specify the subdirectories of a specific directory with ** pattern: bar/**/foo.txt # matches all file...

Any

Any is used to check if any element of a collection matches a condition or not. see also: .All, Any and FirstOrDefault: best practice 1. Empty parameter Any: Returns true if the collection has any elements and false if the collection is empty: var numbers = new List<int>(); bool result = ...
Match any: Must match at least one string. In this example the product type must be either 'electronics', 'books', or 'video'. SELECT * FROM purchase_table WHERE product_type LIKE ANY ('electronics', 'books', 'video'); Match all (must meet all requirements). In this example both 'united...
This query returns all cones with either a mint scoop or a vanilla scoop. minty_vanilla_cones = IceCream.objects.filter(scoops__contained_by=[MINT, VANILLA])
A has_many association indicates a one-to-many connection with another model. This association generally is located on the other side of a belongs_to association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application ...
There are many situation where you want to draw an image that is rotated, scaled, and translated. The rotation should occur around the center of the image. This is the quickest way to do so on the 2D canvas. These functions a well suited to 2D games where the expectation is to render a few hundred e...
Supported by IE11+ View Result Use these 3 lines to vertical align practically everything. Just make sure the div/image you apply the code to has a parent with a height. CSS div.vertical { position: relative; top: 50%; transform: translateY(-50%); } HTML <div class="vertica...
[\+\-]?\d+(\.\d*)? This will match any signed float, if you don't want signs or are parsing an equation remove [\+\-]? so you have \d+(\.\d+)? Explanation: \d+ matches any integer ()? means the contents of the parentheses are optional but always have to appear together '\.' matches '.', we ...

Page 1 of 6