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 7500699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:16:14+00:00 2026-05-29T20:16:14+00:00

I have an array of structures: Public Structure emp Public empName As String Public

  • 0

I have an array of structures:

Public Structure emp
    Public empName As String
    Public empAge As Int32
    Public empsal As Int32 ' salary
End Structure

An array of the above structure with 30 element. I want to sum the empsal of those emp elements whose emp.empName & emp.empAge is equal.

for ex.

emp(0).empName = "test"
emp(0).empAge = 32
emp(0).empsal = 10000

emp(1).empName = "test"
emp(1).empAge = 32
emp(1).empsal = 10000

emp(2).empName = "test12"
emp(2).empAge = 32
emp(2).empsal = 10000

How can this be done so that the result will be (test,20000) and (test12,10000)?

Using .NET 3.5

  • 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-29T20:16:17+00:00Added an answer on May 29, 2026 at 8:16 pm

    EDIT: Edited the samples to include the age in the key, and to end up with an emp array.

    Absolutely. You should look at LINQ for this – you basically want to group by name and age, and then sum the salary. In C# you’d write something like:

    var query = employees.GroupBy
         (x => new { x.empName, x.empAge },
          x => x.empSal,
          (key, salaries) => new emp { empName = key.empName,
                                       empAge = key.empAge,
                                       empSalary = salaries.Sum() })
    var array = query.ToArray();
    

    I think in VB this would be something like:

    Dim query = employees.GroupBy( _
        Function(x) New With { Key .Name = x.empName, Key .Age = x.empAge }, _
        Function(x) x.empSal, _
        Function(k, salaries) New Emp With _
             { .empName = k.Name, .empAge = k.Age, .empSalary = salaries.Sum() }_
        )
    Dim array = query.ToArray()
    

    See the GroupBy documentation for more details.

    As an aside, I would recommend:

    • Giving your type a fuller name which follows .NET naming conventions
    • Making it a class rather than a structure (it’s not really a single value, like an int)
    • Using properties instead of public fields
    • Removing the emp prefix from the fields/properties – they’re already part of an employee type, after all
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of structures. The structure is just some strings. Example public
Here I have: Public Structure MyStruct Public Name as String Public Content as String
I have a huge global array of structures. Some regions of the array are
I have an array structure that looks like this: Array ( [0] => Array
I have the following array structure: Array ( [0] => Array ( [configuration_id] =>
Lets say I have an array with a structure like this: $arr= Array( array(
I have an array that is a member of a structure: $self->{myArray} = [value1,
Does VBA have dictionary structure? Like key<>value array?
How do I convert a structure to a byte array in C#? I have
I have some code intended to get a struct from a byte array: public

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.