score:31
Accepted answer
list<fillstruct> origlist = ...
list<newfillstruct> newlist = origlist.select(x => new newfillstruct {
numlong = x.buy - x.sell, date = x.date
}).tolist();
however, note that struct
is not necessarily a good choice for this (prefer class
unless you have a good reason).
or to avoid linq entirely:
list<newfillstruct> newlist = origlist.convertall(x => new newfillstruct {
numlong = x.buy - x.sell, date = x.date
});
score:4
this will select all your data from the enumerable "fillstructs" and create an enumerable of "newfillstruct" containing the calculated values.
var newfills = from fillstruct in fillstructs
select new newfillstruct
{
numlong = fillstruct.buy - fillstruct.sell,
date = fillstruct.date
};
Source: stackoverflow.com
Related Query
- Use LINQ and C# to make a new List from an old List
- Can I use LINQ to create a new list of objects from an existing list
- How to use Linq to select and group complex child object from a parents list
- How to use linq to assign two lists and an int to create one list of a new object?
- How make a LINQ Select, GroupBy and Count from a List of Lists?
- C# use LINQ to query custom list and return new subset list
- How to execute a linq query for each item in a list , use it in the where clause and return a collection from the result of each query?
- c# Linq or code to extract groups from a single list of source data
- Make a new generic list from a list within a list in Linq with lambda expressions?
- LINQ create new list from elements of outer and inner list
- How do I use LINQ to obtain a unique list of properties from a list of objects?
- Make CSV from list of string in LINQ
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Using Linq and C#, trying to get two lists from a list of master items grouped by two inner lists
- Getting distinct and ordered members from a list of strings - linq or hashset for unique which one is faster / better suited
- Use Linq and lambda to flatten a list
- Using Linq to filter out certain Keys from a Dictionary and return a new dictionary
- How could I use linq when calculating a answer from a symbol and two numbers
- How to use a LINQ in order to remove Min and Max value in List
- How to use LINQ to query list of strings that do not contain substring entries from another list
- Is it possible to use LINQ from F# and how?
- I am trying create a new list of users from a list of users who have not created an additional object with a certain property using LINQ
- LINQ DynamicLibrary: How to extract count and list from IQueryable
- Is possible with LINQ to extract from an array of objects the value of one property and create a new array?
- Linq select strings from list when condition is met and save the index
- LINQ query returns old results when source list is re-initialized
- Linq to return a new object with a selection from the list
- C# - Linq optimize code with List and Where clause
- Make a List of String array from a List of String using LINQ
- Is a full list returned first and then filtered when using linq to sql to filter data from a database or just the filtered list?
More Query from same tag
- Where-Clause in LINQ Dictionary not working
- create an xml with Excel
- ASP .Net: Linq check if string array contains string subarray
- How can I set up a conditional C# if statement and LINQ where statement?
- Combining resultset in C# using Linq
- IQueryable with Linq expression resulting in NullReferenceException
- Unable to get values from XML using xPath C#
- Problems with generic methods and predicates
- how to turn nested foreach loop with C# linq
- React Native JSON Array as Parameter to LINQ Contains
- How to split a List with different chunk sizes efficiently?
- LINQ to entities exception
- Where is the "LEFT" operator in LINQ?
- Intersect and Sum lists with Linq
- Property Selector and Where<T> Query using Linq
- db4o: Query on abstract class type: no results
- DataTable Trickle down duplicate values to last duplicate to fill with most recent data
- Correct syntax to define an IQueryable<TSource>.OrderBy( ) like method
- Generic solution to get default values of all properties in a range of objects
- Remove duplicate objects based on a list properties
- Anonymous types query or normal query in LINQ
- Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator
- How to count multiple column data in linq
- Creating a Dynamic Where Clause as a Linq Expression
- AutoMapper ProjectTo fails with FirstOrDefault
- How to get an empty list of a collection?
- LINQ to Objects, query arrays in object
- Can't convert string to number type in xml query
- Generic List Find using lambda expression in c#
- Where does "i" get its value in this LINQ statement?