This may be novel or really dumb, but I like it. Say you want to convert a Dictionary to a List of KeyValuePairs that are sorted by something within the dictionary Key or Value. Don’t ask why, just go with it. You could do this: Where someDictionary is Dictionary<Type, string> : List<KeyValuePair<Type, String>> dataSource = [...]
Using the ForEach method on List Collections
public static StateCollection GetByName(String partialName) { StateCollection returnValue; returnValue = new StateCollection(); //baseList is some list I wasn’t nice enough to show where it came from. //It’s just a list of states. Get over it. var stateList = from state in baseList where state.Name.StartsWith(partialName) select new State(state.Name, state.Code); stateList.ToList().ForEach(currentState => returnValue.Add(currentState)); return returnValue; } So [...]
Filling a list of classes with random values using linq
Filling a list of classes (10 for this example) with random values using linq. Enumerable.Range(0, 10) – This means give me a list from 1 to 10 Enumerable.Range(0, 10).Select ( j => – This means you are going to select every j in the list Enumerable created Enumerable.Range(0, 10).Select ( j => new JunkItemB() – [...]