Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 577455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:09:18+00:00 2026-05-13T14:09:18+00:00

I have a class as follows: Class Scan Delivered As Boolean ScanDate As Date

  • 0

I have a class as follows:

Class Scan
    Delivered As Boolean
    ScanDate As Date
    State As String
    Facility As String  
End Class

I then create a list and populate it with scans containing whatever.

Dim Scans As New List(Of Scan) 

I need to mine the list to get various pieces of information. I would like to use LINQ to do it. The problem is that for the life of me, I just don’t get it. The syntax throws me off, the fact that the results are not strongly typed throws me off, and the sample on the web are oversimplified, or overcomplicated.

How could I

  1. Get a count of scans, grouped by Date where Delivered = True
  2. Get a count of scans, grouped by Facility where Delivered = True
  3. Get a count of scans, grouped by State where Delivered = True

I then want to use this in a For Each loop.

For Each result In GroupedResults
    ‘My Code

Next

Ideally, I’d like the result to be strongly typed. Is this possible?

Can anyone recommend some links to get started with this? Every web site I come across just gets my head swimming. I’m not understanding it at all.

EDIT:

Thank you so much guys. I’m still scratching my head over this stuff , but at least this is a real world example I can use to get an idea of what is going on.

I was hoping that this simple example would help me spring board into a more complex use – no luck yet. I should have asked this off the bat.

All the examples seem to use a key/value response. What if I have two values I need grouped?

    Class Scan
        Delivered As Boolean
        Scanned As Boolean
        ScanDate As Date
        State As String
        Facility As String  
    End Class


1. Get a count of Delivered = True,  a count  of Scanned=True, grouped by Date 
2. Get a count of Delivered = True,  a count  of  Scanned=True, grouped by Facility 
3. Get a count of Delivered = True,  a count  of Scanned=True, grouped by State 

Is it possible to get this in one result?

Edit Edit:

Answered my own Edit! This seems to be working for me:

Dim query = From r In scans _
            Group r By r.ScanDate Into g = Group _
            Select New With _
            {g, .DeliveredCount = g.Count(Function(s) s.Delivered), .ScannedCount = g.Count(Function(s) s.Scanned)}

Thank you so much guys. You got me to the point where I could hack a solution out. I still don’t “get” what I’m doing (What is Function(s)?!), but I’ve got something to start with. I intend to spend time learning this now. I think what really threw me off is that the samples on the net are C#. Normaly I have no problem converting the syntax, but with LINQ this is not as simple. I thought I was doing something wrong, but it was just that the syntax was very different.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:09:19+00:00Added an answer on May 13, 2026 at 2:09 pm

    You are not limited of using LINQ’s query syntax. You can also use the LINQ extension methods on the collections.

    The result that you’ll receive will be strongly typed. Although anonymous types will be used when you do not return an existing type.

    The code below is C#, but you’ll understand:

    static void Main( string[] args )
    {
        List<Scan> scans = new List<Scan> ();
    
        scans.Add (new Scan (new DateTime (2010, 1, 1), true, "Facility1"));
        scans.Add (new Scan (new DateTime (2010, 1, 1), true, "Facility2"));
        scans.Add (new Scan (new DateTime (2010, 1, 1), false, "Facility3"));
        scans.Add (new Scan (new DateTime (2010, 1, 26), true, "Facility1"));
    
        var result1 = scans.Where (s => s.Delivered).GroupBy (s => s.ScanDate);
    
        foreach( var r in result1 )
        {
            Console.WriteLine (String.Format ("Number of delivered scans for {0}: {1}", r.Key, r.Count ()));
        }
    
        var result2 = scans.Where (s => s.Delivered).GroupBy (s => s.Facility);
    
        foreach( var r in result2 )
        {
            Console.WriteLine (String.Format ("Number of delivered scans for {0}: {1}", r.Key, r.Count ()));
        }
    
        Console.ReadLine ();
    
    }
    

    The result here is not really typed, since a GroupBy expression returns an IGrouping type.
    However, you can get around this, by doing this:

     var result2 = scans.Where (s => s.Delivered)
                        .GroupBy (s => s.Facility)
                        .Select( s => new { Facility = s.Key, NumberOfItems = s.Count() } );
    

    Using the extension methods that LINQ provides, may perhaps help you understanding it a bit more.

    Sorry for the C# syntax, but I’m not really familiar with VB.NET.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some classes defined as follows: class Security { Boolean AuthenticateUser(String
I have a class as follows :- interface IFilterCondition { List<Name> ApplyFilter(List<Name> namesToFilter); }
I have a class as follows Public Class Foo Private _Name As String <ShowInDisplay()>
I have ViewModel class as follows: public class ListViewModel { public ObservableCollection<InfoItem> List {
I have a class as follows class DataGridItem { public bool IsSpecial; public string
I have a class that follows the form: public class Cat { public string
I have the C# class as follows : public class ClassInfo { public string
I have a class as follows: public class Document { public List<DocumentSection> sections =
I have a class as follows: class TestSomeData { public string someString; public void
I have a class A as follows: class A { public: A() { printf(A

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.