score:2
Accepted answer
var setOne = new HashSet<string>(textBoxWords.Text
.Split(new char [] { '\r', '\n' })
.Select(s1 => s1.Trim())
.Where(s2 => !String.IsNullOrEmpty(s2)));
It's not exactly the same as what you have since the result is a HashSet, but based on your scenario it looks like that may be the better data structure for what you are trying to accomplish.
score:1
Your examples are already fairly simple. One alternative would be:
(from s in textBoxWords.Split(new char[] { '\r', '\n' })
where !string.IsNullOrEmpty(s)
select s.Trim()).Distinct();
Source: stackoverflow.com
Related Articles
- Are these the simplest ways to apply several different actions to a list of strings using LINQ?
- Why do these three pieces of LINQ code produce different (or erroneous) results?
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- Code to apply expression tree directly to List
- Create one List from several different lists of the same type with C#
- Sort List with two parameters but in different lines of code
- How will works this different ways to select a subset in a list by type
- List or Array of String Contain specific word in Html Source Code
- c# Linq or code to extract groups from a single list of source data
- Why there is two completely different version of Reverse for List and IEnumerable?
- How to merge several arrays in a List using Linq?
- Simplest way to filter value from generic List in C# using LINQ
- Different ways of using SelectMany()
- Exclude items of one list in another with different object data types, LINQ?
- Comparing 2 objects and retrieve a list of fields with different values
- Generating the Shortest Regex Dynamically from a source List of Strings
- Can someone explain why these two linq queries return different results?
- Linq query to exclude from a List when a property value of List of different type are equal?
- LINQ Query - Explanation needed of why these examples are different
- How do you query several tables at once given a list of table names as strings?
- LINQ Source Code Available
- Difference of two List with different types using LINQ
- Is it possible to ignore a list item using the Skip method of the LINQ then apply skip on the list without losing that item?
- How to have a list with different data types of lists in it as a sublists?
- .NET 4 Code Contracts: "requires unproven: source != null"
- Linq - Excluding items from different list types
- merging two different string lists to a class list
- Apply a linq expression of an object to a list of items where that object is a propery of an item (Wrapper)
- Apply lambda expression for specific indices in list c#
- Apply a predicate on all elements of a list using LINQ
- LINQ: How to force a value based reference?
- Implement pagination using LINQ (on the server side)
- How to select from 3 tables in a series using Linq?
- Get all the variables of a SQL Dataset that are the max of a sort order using LINQ
- How to use LINQ to search and item from the database
- Pushing Items into stack with LINQ
- How to get Count in Lambda
- Invalid Arguments - cannot convert Anonymous Type#2
- Linq query where there's a certain desired relationship between items in the result
- Can't convert string to number type in xml query
- Writing a linq Query to add elements with duplicate IDs together
- Write a Query which selects user name associated with a session id
- How should I change this source into LINQ?
- How to create a DropDownList from a LINQ query in MVC3?
- complex LINQ multiple tables with many to many
- Create a LINQ for the List<> to fetch records based on conditional parameters
- Union-ing two custom classes returns duplicates
- How to extract a where clause expression tree from IQueryable
- LINQ: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<int>' to 'int'
- DataGridView delete row when DataSource is List<myClass>