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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:45:40+00:00 2026-05-29T22:45:40+00:00

public struct PLU { public int ID { get; set; } public string name

  • 0
public struct PLU
{ 
    public int ID { get; set; } 
    public string name { get; set; } 
    public double price { get; set; } 
    public int quantity {get;set;}
}

public static ObservableCollection<PLU> PLUList = new ObservableCollection<PLU>();

I have the ObservableCollection as above. Now I want to search the ID in the PLUList and get its index like this:

int index = PLUList.indexOf();
if (index > -1)
{
    // Do something here
}
else
{
    // Do sth else here..
}

What’s the quick fix?

EDIT:

Let’s assume that some items were added to PLUList and I want to add another new item. But before adding I want to check if the ID already exists in the list. If it does then I would like to add +1 to the quantity.

  • 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-29T22:45:41+00:00Added an answer on May 29, 2026 at 10:45 pm

    Use LINQ 🙂

    var q =  PLUList.Where(X => X.ID == 13).FirstOrDefault();
    if(q != null) 
    {
       // do stuff
    }
    else 
    {
       // do other stuff
    }
    

    Use this, if you want to keep it a struct:

    var q =  PLUList.IndexOf( PLUList.Where(X => X.ID == 13).FirstOrDefault() );
    if(q > -1) 
    {
       // do stuff
    }
    else 
    {
       // do other stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public struct customerItemListStruct { public int ID { get; set; } public string name
Consider the following struct: public struct vip { string email; string name; int category;
public struct Cache { public int babyGangters { get; set; } public int punks
Is this valid? public struct MyStruct { public int Foo { get; set; }
Code to illustrate : public struct MyStruct { public int SomeNumber; } public string
public struct Items { public string Id; public string Name; } public Items[] _items
consider the following class and struct public class Entity { public IdType Id {get;set;}
I have a struct like this: public struct MyStruct { public string Name; public
public struct Parameter { public Parameter(string name, string type, string parenttype) { this.Name =
I have some example data: public struct Task { public int INT; public string

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.