Questions tagged [linq-to-objects]

The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable or IEnumerable collection directly, without the use of an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML.

The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable or IEnumerable<T> collection directly, without the use of an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML.

For example, say that myCats is a list of Cat objects. Then you can pick your favorite cat by using:

Cat myFavorite = myCats.Single(c => c.Score == myCats.Max(x => x.Score));

To get an alphabetical listing of your cats, use this:

var listing = myCats.OrderBy(c => c.Name);

To get all cats that have caught more than 20 mice, use the following:

var champions = myCats.Where(c => c.MiceCaught.Count > 20);

You can also use a more SQL-like syntax:

var champions = from cat in myCats where cat.MiceCaught.Count > 20 select cat;

LINQ to Objects thus uses the same familiar syntax as the other LINQ implementations such as LINQ to Entities and LINQ to SQL.

1347 questions
-1
votes
4 answers

LINQ - Convert to LAMBDA Expression

foreach (int i in temp) data.Add(i); where temp is a List and data is an ObservableCollection
-1
votes
1 answer

How to select common items

Work on C# linq.I have a list to list.From this list I want to get the common items List oParent = new List(); List> oChild = new…
shamim
  • 6,186
  • 19
  • 71
  • 139
-1
votes
3 answers

Generic collection fill by var value

In my code, I need help to put result value into oList NorthwindDataContext db = new NorthwindDataContext(); List oList = new List(); var result = from p in db.Categories select new { CategoryID = p.CategoryID,…
shamim
  • 6,186
  • 19
  • 71
  • 139
-1
votes
1 answer

trying to use linq aggregate function

I have below query where i am using the where clause with select and getting the result (list of librarySourceRowInputs) and would like to use the aggregate instead of (where and select). In this process I am trying to access the same variables…
Enigma State
  • 16,494
  • 25
  • 86
  • 179
-1
votes
1 answer

Need to determine smallest value in a List

I'm stuck at something that seemed easy but became a headache pretty fast: Here is a class that represent a structure I'm using: public class LocumJobDistanceDifferenceObject { public LocumJobDistanceDifferenceObject(Int64 ALocumID, Int64…
Hassan Gulzar
  • 3,852
  • 4
  • 35
  • 69
-1
votes
2 answers

How can i use LINQ with property

Hi I have a array list if type class "DtContract". ArrayList listOfContracts_; foreach (DTContract contract in listOfContracts_) { if (contract.Engine != DTIsland.EngineType.AMADEUS && contract.Engine !=DTIsland.EngineType.SABRE) …
Shivi
  • 1,047
  • 9
  • 23
  • 41
-1
votes
1 answer

LINQ .NET 4.0 - WHERE alone OK - ORDERBY alone OK - WHERE and ORDERBY Fails

Below runs correctly without error: IEnumerable FieldDefQuery = from fds in FieldDefs where fds.DispLevel == enumDispLevel.Grid select fds; Below runs correctly without error: IEnumerable FieldDefQuery = …
paparazzo
  • 42,665
  • 20
  • 93
  • 158
-1
votes
2 answers

Filtering Object values in C#

i've got a C# web Api receiving the following object : "cars": { "bmw": true, "benz": false, "kia": true, "hyundai": false, "madza": false, "ford": false } the class property is as follows : public…
Silva
  • 405
  • 1
  • 3
  • 13
-1
votes
1 answer

Last() with arrays

How effective is using Last() for arrays? var array = new[] { ... }; var last = array.Last(); // or array[array.Length - 1] In sources it only distinguish IList, so is that true what Last() will enumerate a complete array to return last item?…
Sinatr
  • 18,856
  • 9
  • 75
  • 248
-1
votes
1 answer

Linq ToDictionary anonymous versus concrete types

I am trying to use Linq to convert a list to Dictionary. I have been able to get proper results with anonymous types as keys, but not with concrete types. Please see code snipped below: // Works. Produces 329 entries in dictionary, as…
Amit
  • 1,775
  • 12
  • 20
-1
votes
3 answers

How to GroupBy time-range (closed-times grouped together)

Assume we have this records: NID CId PushedAt 120 796 2015-09-04 18:00:53.6012627 +00:00 120 967 2015-09-04 18:00:51.9891748 +00:00 119 669 2015-09-04 17:45:56.8179094 +00:00 119 955 2015-09-04 17:45:55.2078154…
amiry jd
  • 18,602
  • 10
  • 58
  • 127
-1
votes
1 answer

LINQ Compare Two Genreic Same Type of List and Get Result of Which item added,removed and nochange

I have two Lists List previous=new List() { new Employee() { Id = 1, Name = "1" }, new Employee() { Id = 2, …
Nilesh Moradiya
  • 651
  • 1
  • 9
  • 18
-1
votes
1 answer

ORing LINQ Query in linq to object, built using expression trees

I want same field combine with ORs and between two diffferent fileds with AND. ex - If they have the same Field value, those all ORed. This allows us to say "State", "eq", "CA", OR "State", "eq", "TX" AND "FirstName", "eq", "John". (State==CA ||…
MDev
  • 41
  • 4
-1
votes
2 answers

Select distinct value with where clause for a datatable

I have a datatable. I am getting distinct value of column from below code. AllFields is my datatable. var distinctIds = AllFields.AsEnumerable() .Select(s => new { id = s.Field(ColumnName), }) .Distinct() …
Rohit
  • 69
  • 1
  • 7
-1
votes
2 answers

Convert list of objects in object to csv

In vb.net How to convert a list of objects within another List of Objects to csv string. I tried below didn't work String.Join(",", Person.Cars.Select(Function(d) d.Colors.Select(Function(o) o.colorid.ToString))) Output should be colorid in string…
Gauls
  • 1,791
  • 5
  • 27
  • 43