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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:53:07+00:00 2026-06-06T15:53:07+00:00

I am trying to learn how to use lists in C#. There are a

  • 0

I am trying to learn how to use lists in C#. There are a lot of tutorials out there, but none of them really explain how to view a list that contains a record.

Here is my code:

class ObjectProperties
{
    public string ObjectNumber { get; set; }
    public string ObjectComments { get; set; }
    public string ObjectAddress { get; set; }
}

List<ObjectProperties> Properties = new List<ObjectProperties>();
ObjectProperties record = new ObjectProperties
    {
        ObjectNumber = txtObjectNumber.Text,
        ObjectComments = txtComments.Text,
        ObjectAddress = addressCombined,
    };
Properties.Add(record);

I want to display the values in a messagebox. Right now I am just making sure the information is going into the list. I also want to learn how to find a value in the list and get the other information that is related to it, such as, I want to find the item by the Object Number and if it is in the list then it will return the address. I am also using WPF, if that makes a difference. Any help will be appreciated. Thank You.

  • 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-06-06T15:53:10+00:00Added an answer on June 6, 2026 at 3:53 pm

    The best way is to override ToString in your class and use string.Join to join all your records:

    var recordsAsString = string.Join(Environment.NewLine, 
                Properties.Select(p => p.ToString()));
    MessagBox.Show(recordsAsString);
    

    Here’s a possible implementation of ToString:

    class ObjectProperties
    {
        public string ObjectNumber { get; set; }
        public string ObjectComments { get; set; }
        public string ObjectAddress { get; set; }
    
        public override string ToString() 
        {
            return "ObjectNumber: " 
                  + ObjectNumber 
                  + " ObjectComments: " 
                  + ObjectComments 
                  + " ObjectAddress: " 
                  + ObjectAddress;
        }
    }
    

    I also want to learn how to find a value in the list and get the other information that is related to it, such as, I want to find the item by the Object Number and if it is in the list then it will return the address.

    There are several ways to search a List<T>, here are two:

    String numberToFind = "1234";
    String addressToFind = null;
    // using List<T>.Find method
    ObjectProperties obj = Properties.Find(p => p.ObjectNumber == numberToFind);
    //using Enumerable.FirstOrDefault method (add using System.Linq)
    obj = Properties.FirstOrDefault(p => p.ObjectNumber == numberToFind);
    if (obj != null)
        addressToFind = obj.ObjectAddress;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn how to use WinForms databinding, but one thing that's confusing
Just trying to ping up some experienced Thread gurus out there...trying to learn more
I am trying to learn and use an SDK for a vendor's product. Unfortunately,
I am trying to learn to use buffer overflow attack in Ubuntu. Unfortunately, I
I am trying to learn to use the wx packages to make GUI programs
I am relatively new to programming, and I am trying to learn to use
I'm trying to learn how to use oop in php. I'm also fairly new
I'm trying to learn how to use lift. I can create project skeleton by
I'm trying to learn how to use actionscript over mxml for flexibility. I have
I'm trying to learn how to use the UITableView in conjunction with a SQLite

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.