If you have a collection of class object and you want to extract an array or list of only one of the properties, lot of time we end up writing code that iterates over each item and then putting it in a new array or list. There is a clean and quick way of doing it using Linq. Following code snippet shows how I extracted an array of ingredient names from a List of Ingredient class objects.
public string[] SearchIngredient(string prefixText, int count) { var ingredientsList = IngredientData.GetIngredientsWithNameLike(prefixText); if (null == ingredientsList || ingredientsList.Count == 0) {return null;} var nameQuery = from ingredient in ingredientsList select ingredient.Name; return nameQuery.ToArray(); }
Learn Python: How to format date in Python
0x1F is an invalid start of a value
Learn Python: How to ignore SSL verification for HTTP requests
How to host your web site from your home
Automate testing of web page element transition with Selenium
Alert and Confirm pop up using BootBox in AngularJS
AngularJS Grouped Bar Chart and Line Chart using D3
How to lock and unlock account in Asp.Net Identity provider
2022 © Byteblocks, ALL Rights Reserved. Privacy Policy | Terms of Use