score:11
Accepted answer
what about introducing a temporary variable inside the select
:
sorderby.split(',').select(x =>
{
var trimmedsplitted = x.trim().split(' ');
return new orderbycolumn()
{
columnname = trimmedsplitted[0].trim(),
isascending = (trimmedsplitted[1].trim() == "asc")
};
}
).tolist<orderbycolumn>()
score:0
you just add an extract select:
sorderby.split(',').
select(x => x.trim().split(' ')).
select(x => new orderbycolumn(){
columnname = x[0].trim(),
isascending = x[1].trim() == "asc"}).
tolist()
i hope this work out for you.
score:4
sorderby.split(',')
.select(csv=> csv.trim().split(' '))
.select(splitbyspaces => new orderbycolumn()
{
columnname = splitbyspaces[0].trim(),
isascending = (splitbyspaces[1].trim() == "asc")
})
.tolist<orderbycolumn>()
Source: stackoverflow.com
Related Query
- Multi-delimited string to list of objects using linq and lambdas
- Match a comma delimited string to an integer list using linq and return the new objects
- Sort a list and all its nested objects using LINQ
- Linq To XML - Using XDocument and creating list of objects
- LINQ - Sort List of objects using OrderBy EnumValue, and Union result set?
- How to get a complement list of objects using linq and EntityFramework
- Read xml using LINQ and store in a list of objects
- Extract list of objects from a string using linq
- Convert delimited string to array and group using LINQ in C#
- How to search a list of objects for a specific string attribute using LINQ in C#
- Filter list of entity objects by string child object property using Linq Lambda
- Linq Intersect Comma Delimited String with List Containing Strings using Iqueriable
- Join a string property which is in a List of objects using Linq
- Sorting list of Objects using LINQ and private IComparer?
- Find a string in the list and change value of another property using linq (complicated)
- Using linq to sort list of objects with string property
- Read from XML Using Linq and add it to a list containing objects
- Group a list of anonymous type objects using linq and lambda
- Check String contain all elements in list using Linq and case insensitive
- Building an string from properties values of objects in a list using linq
- Update a property on objects in a list and add it to another list without editing the original list using LINQ
- Return select objects and only desired subvalues from a list of lists using LINQ
- Using a list of Json results as parameters for a mvc actionresult, to return objects from database with Linq and Lambda
- Access two indexes in a list and create a list of new objects using Linq
- Extract key and value from a List of a List of objects using LINQ
- Using Linq to query objects from a database and checking if they exit in a another list or array
- Searching if value exists in a list of objects using Linq
- Convert list to dictionary using linq and not worrying about duplicates
- Using Linq to group a list of objects into a new grouped list of list of objects
- compare two list and return not matching items using linq
More Query from same tag
- "Filtering" a collection before starting a Linq query on it
- Linq for updating property of A.property with matching B.property where A.Key == B.Key
- Efficient way to loop through data to return Object in Web api c#
- Run an IQueryable with Entity Framework
- Tell LINQ Distinct which item to return
- Summing by multiple columns in a list
- Search in list of class propertie-values where equal to a property set values
- dynamically select fields in linq
- Search Specific Duplicated keys in List C#
- Call method in Linq Select() without loading whole object
- C# find xml element matching two element levels using linq
- Generic type inference
- Find invalid character check against string array in C#
- Comparing two custom objects
- LINQ Select()/Any() misbehaving?
- What is the difference between ((IEnumerable)source).OfType<T>() and source as IEnumerable<T>
- Expanding an IDictionary<Key, IEnumerable<Value>>
- Is there an IEnumerable implementation that only iterates over it's source (e.g. LINQ) once?
- How do I select multiple grandchildren in linq?
- Sort list of lists using LINQ so high score is first then lastname and firstname in alphabetic order
- C# how do I implement inheritance using linq?
- Select data from multiple unrelated tables with LINQ to Entity Framework
- Un-Nesting List Iterations for Performance
- Using aggregates on multiple tables in Linq to SQL
- LINQ GroupBy continuous time
- C# Convert a DataTable to List<string>
- Select values from DataGridViewCellCollection using Linq
- Usage OrderBy in LINQ firstly the Cyrillic words then the Latin words
- testing for no return from LINQ
- Parsing an Excel file in C#, the cells seem to get cut off at 255 characters... how do I stop that?