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

  • Home
  • SEARCH
  • 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 146801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:40:05+00:00 2026-05-11T08:40:05+00:00

I have a struct containing song data: public struct uLib { public string Path;

  • 0

I have a struct containing song data:

public struct uLib     {         public string Path;         public string Artist;         public string Title;         public string Album;         public string Length;     }   

My library consists of an array of this uLib. How would I sort this array by say Artist? Is there a native sort function I can call on this type of array, or will I have to ‘roll my own’?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T08:40:05+00:00Added an answer on May 11, 2026 at 8:40 am

    First of all, that should not be a struct. It’s larger than 16 bytes, so you don’t get the performance benefits of having a struct. Also, it doesn’t represent a single value, so it doesn’t make sense semantically to make it a struct. Just make it a class instead.

    The Array class has a Sort method that you can use:

    Array.Sort(theArray, (x,y) => string.Compare(x.Artist,y.Artist)); 

    If you don’t have C# 3 you use a delegate instead of the lambda expression:

    Array.Sort(theArray, delegate(uLib x, uLib y) { return string.Compare(x.Artist,y.Artist) } ); 

    Edit:
    Here’s an example of what your data could look like as a class:

    public class ULib {      private string _path, _artist, _title, _album, _length;      public string Path { get { return _path; } set { _path = value; } }     public string Artist { get { return _artist; } set { _artist = value; } }     public string Title { get { return _title; } set { _title = value; } }     public string Album { get { return _album; } set { _album = value; } }     public string Length { get { return _length; } set { _length = value; } }      public ULib() {}      public ULib(string path, string artist, string title, string album, string length) {        Path = path;        Artist = artist;        Title = title;        Album = album;        Length = length;     }  } 

    In C# there there is a short form for a property. Instead of writing code for a private variable and a setter and getter to access it, this creates that automatically:

    public string Path { get; set; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 166k
  • Answers 166k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ended up using CLIENT_HOST to call an FTP command… May 12, 2026 at 1:17 pm
  • Editorial Team
    Editorial Team added an answer Yarg! I finally figured it out when doing the auto… May 12, 2026 at 1:17 pm
  • Editorial Team
    Editorial Team added an answer Ok, how about this instead: (defun my-font-lock-restart () (interactive) (setq… May 12, 2026 at 1:17 pm

Related Questions

I am using ECPG with PostgreSQL 8.4. I have a function which takes a
I have a file in C++ containing constant definitions, I want to use the
I am attempting to copy the members of a struct containing a mixture of
I have a memory block that is divided into a series of location that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.